我正在嘗試將這兩個呼叫合并為一個,以便它們呼叫異步或后續呼叫。我在想我必須使用 map 或 switchMap。
imageType 是一個列舉。
它應該作為字串 uri 回傳。
列舉
export enum ImageType {
Avatar = 1,
Cover = 2
}
組件.ts
this.service.getphotos(ImageType.Avatar, this.id).subscribe(result => {
this.avatarPhotos = result;
});
this.service.getphotos(ImageType.Cover, this.id).subscribe(result => {
this.coverPhotos = result;
});
服務.ts
getPhotos(imageType: ImageType, id: number): Observable<string[]> {
return this.http.get<string[]>(`api/getphotos/${imageType}/${id}`);
}
uj5u.com熱心網友回復:
簡單的解決方案,在這里:
combineLatest([
this.service.getphotos(ImageType.Avatar, this.id).pipe(
tap(result => (this.avatarPhotos = result)),
),
this.service.getphotos(ImageType.Cover, this.id).pipe(
tap(result => (this.coverPhotos = result)),
)
]).subscribe()
你可以用forkJoin任何一個來做到這一點。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/372520.html
上一篇:型別覆寫類內的型別
