I have successfully displayed my playlist but I would like to add the number of videos to each playlist.
For that I have to send another request. I can't merge the number of videos in my playlist result
Thank you for your help, 3 days without results
My yt.service.ts
getPlaylistsForChannel(channel): Observable<any[]> {
return this.http
.get<any[]>(
"https://www.googleapis.com/youtube/v3/playlists?key=" +
this.apiKey +
"&channelId=" +
channel +
"&part=snippet,id&maxResults=20"
)
.pipe(
catchError(err => of([])),
map(res => {
return res["items"];
})
);
}
getListVideos(listId): Observable<any[]> {
console.log(listId);
return this.http
.get<any[]>(
"https://www.googleapis.com/youtube/v3/playlistItems?key=" +
this.apiKey +
"&playlistId=" +
listId +
"&part=snippet,id&maxResults=20"
)
.pipe(
catchError(err => of([])),
map(res => {
console.log(res["items"]);
return res["items"];
})
);
}
my playlists.ts
searchPlaylists() {
this.playlists = this.ytService.getPlaylistsForChannel(this.channelId);
let that = this;
this.playlists = this.playlists.pipe(
catchError(err => of([])),
mergeMap(res => {
let nb = res.length;
for (let i = 0; i < nb; i++) {
that.ytService.getListVideos(res[i].id).pipe(
map(res2 => {
res.number = res2.length;
})
);
}
console.log(res);
return res;
})
);
}