I created an API that shows a user's followers and following users. Everything is displaying correctly on the screen. However, when I try to use console.log()
to display the array it is stored in after calling the method, it shows as an empty array. I'm stuck and not sure what to do next. Can someone help or does anyone else have the same issue? Please let me know.
ngOnInit:
ngOnInit(): void {
localStorage.setItem("gd", "78F88FC0-7A58-49CD-881E-4B36C5C29B71");
this.getUsers();
this.getFollowing();
this.getFollowers();
console.log("Followers: ", this.followers)
console.log("Following: ", this.following)
}
Methods:
getUsers() {
this._userService.getUsers().subscribe(res => {
this.users = res;
})
}
getFollowing() {
this._userService.getFollowing().subscribe(res => {
this.following = res;
})
}
getFollowers() {
this._userService.getFollowers().subscribe(res => {
this.followers = res;
})
}
Console:
https://i.sstatic.net/K2mhV.png
HTML output:
https://i.sstatic.net/LswQd.png