如何在管道方法中提取可观察的结果?我有以下内容:
// type of "observables" is Observable<Observable<MyType>[]>
const observables = this.http.get<MyTypeList>(rootUrl).pipe(
map(list => list[locale]),
map(urlList => urlList.map(url => this.http.get<MyType>(url))),
// I need some method here to make Observable<MyType>[] from Observable<Observable<MyType>[]>
);
forkJoin(observables).subscribe(/* I have all my items here*/)
在第二次map
通话后,我需要一些方法从Observable<MyType>[]
制作Observable<Observable<MyType>[]>
这是否有一种优雅的方法?
答案 0 :(得分:0)
问题是我曾尝试在外面使用forkJoin,我想我可以在建议的mergeMap
里面使用它。
const obs = this.http
.get<MyTypeList>(rootUrl)
.pipe(
map(list => list[locale]),
mergeMap(urlList =>
forkJoin(
urlList.packages.map(url => this.http.get<MyType>(url))
)
)
);
obs.subscribe(/* I have all my items here*/);