.pipe(
switchMap(x => { return this.clientService.A(); }),
filter(firstResp => Helpers.IsNotNull(firstResp)),
switchMap(firstRep => { return this.clientService.B(firstResp.someProp); }),
).subscribe(
//Want to access response of both services in subscribe method.
);
第一个SwitchMap正在返回服务A的响应,该响应将进入第二个SwitchMap。在这个Subscribe方法中,我需要使用两个switchMap响应。我怎样才能做到这一点?
注意-两种服务响应类型不同。
您可以嵌套管道:
.pipe(
switchMap(x => this.clientService.A()),
filter(firstResp => Helpers.IsNotNull(firstResp)),
switchMap(firstRep => this.clientService.B(firstResp.someProp)
.pipe(map(b => [firstRep, b]))),
).subscribe(([a, b]) => {
// stuff
});