我已成功显示我的播放列表,但我想将视频数量添加到每个播放列表。
为此,我必须发送另一个请求。我无法合并播放列表结果中的视频数量
感谢您的帮助,3天没有结果
我的 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"];
})
);
}
我的播放列表.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;
})
);
}