import { Component, OnInit } from '@angular/core'; import { FriendsService } from '../../services/friends/friends.service'; import { NgFor, NgIf } from '@angular/common'; @Component({ selector: 'app-friend-page', imports: [NgFor, NgIf], templateUrl: './friend-page.component.html', styleUrls: ['./friend-page.component.css'] }) export class FriendPageComponent implements OnInit { protected listFriend: {username: string, status: string, friend_user_id: string}[] = []; userId: string = ""; status: string = ""; constructor(private friendService: FriendsService) { } ngOnInit(): void { this.getFriendData(); console.log(this.listFriend) } private getFriendData(): void { this.friendService.getFriend().subscribe((data: any[]) => { if (data.length > 0) { data.forEach(friend => { let status = friend['status']; let userId = friend['friend_user_id']; this.friendService.getFriendById(userId).subscribe((friendData: any) => { this.listFriend.push({ username: friendData.username, status: status, friend_user_id: userId }); }); }); } }); } onAcceptOrDeny(friend_user_id: string, choice: string){ this.friendService.acceptOrDenyFriendById(friend_user_id,choice).subscribe() } }