rxjs使用combineLatest避免嵌套订阅



我需要修复这个嵌套订阅,但我遇到了一些困难:-(你能帮我找到解决办法吗?

combineLatest([stream1,stream2])
.pipe(takeUntil(this.destroyed$))
.subscribe({
next: ([a, b]) => {
this.extService.get(a,b).subscribe();
},
});

在这种情况下,您必须在之后使用切换映射,这样它将"改变";到新的订阅

combineLatest([stream1,stream2])
.pipe(
takeUntil(this.destroyed$),
switchMap(([a,b])=>this.extService.get(a,b)
)
)
.subscribe(
(responseFromExtService) => { // your code}
);

确保你也知道联合lastest和fork-join 之间的区别

最新更新