Observable按顺序发出并从前一个输入

问题描述 投票:1回答:1

我有2个观察者,第2个观察者以第1个作为参数。代码看起来如下,但o2$怎么能回归o1$

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

o1$.pipe(
    map(data => data['id']),
    concat(o2$)
).subscribe(x => log('completed'));
angular rxjs observable
1个回答
0
投票

您可以在这里使用flatMap,如下所示:

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

o1$.pipe(
    flatMap(data => this.apiService.get2(data['id'])),
).subscribe(x => log('completed'));
© www.soinside.com 2019 - 2024. All rights reserved.