I know it was asked million times, but i really don't understand how it works. I tried to new Promise, but there is nothing inside then()
i tried to do it with mergeMap but messed up.
I want to get current user's favorite items. And to do it i'm calling this method:
user: IUser;
tracks: ITrack[] = [];
public getFavorites() {
this.userService.getFavourite(this.user.id).subscribe(
(tracks: ILike[]) => {
if (tracks) {
tracks.forEach(track => {
this.tracks.push(this.loadTracks(track.id));
});
}
}
);
For this method i need user id which i get like this and :
private async loadUser() {
this.accountService.currentUser$.subscribe((user: IUser) => {
// getting into another service, because currentUser don't have id
this.userService.getUserByUsername(user.username).subscribe((u: IUser) => {
this.user = u;
})
})
}
and and also track_id:
loadTracks(id: number) {
let track: ITrack;
this.trackService.getTrack(id).subscribe(t => track = t);
return track;
}
ngOnInit():
this.loadUser();
this.getFavorites();
How to do it properly with mergeMap?