Observable按顺序发出并从上一个获得输入

时间:2018-11-01 11:38:26

标签: angular rxjs observable

我有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'));

1 个答案:

答案 0 :(得分:0)

您可以在此处使用flatMap,如下所示:

let o1$ = this.apiService.get1();

o1$.pipe(
    flatMap(data => this.apiService.get2(data['id'])),
).subscribe(x => log('completed'));