I have an app in ANGULAR and RXJS I don't understand something. I'm trying to get a value from an observable and modify it afterward.
export class FavoritesComponent implements OnInit {
test: any[] = [];
constructor(private userService: UserService) { }
ngOnInit(): void {
this.getUserInfosFav();
console.log(this.test);
this.loadFavoris();
}
getUserInfosFav() {
const idUser = this.userService.decodeToken().id;
return this.userService.getUserInformations(idUser)
.subscribe({
next: (v) => this.test.push(v),
error: (e) => console.error(e),
complete: () => console.info('complete')
})
}
loadFavoris() {
console.log(this.test)
this.test.forEach(val => console.log(val))
In loadFavoris()
I'm just trying to loop the test array with the value but when I try looping over it and then logging in the console, it shows nothing.
This is the value of the API CALL
[
{
"@context": "/api/contexts/User",
"@id": "/api/users/114",
"@type": "User",
"email": "test@test.com",
"firstname": "tes put ",
"lastname": "test put ",
"favorites": [
{
"@id": "/api/favorites/17",
"@type": "Favorite",
"idSneaker": "367"
},
{
"@id": "/api/favorites/18",
"@type": "Favorite",
"idSneaker": "366"
}
],
"inventories": []
}
]