我有2个可观察值,而第二个则以第一个的返回值作为参数。该代码如下所示,但是o2$
如何获取o1$
的返回值?
let o1$ = this.apiService.get1();
let o2$ = this.apiService.get2();
o1$.pipe(
map(data => data['id']),
concat(o2$)
).subscribe(x => log('completed'));
答案 0 :(得分:0)
您可以在此处使用flatMap
,如下所示:
let o1$ = this.apiService.get1();
o1$.pipe(
flatMap(data => this.apiService.get2(data['id'])),
).subscribe(x => log('completed'));