rxjs 避免使用 combineLatest 进行嵌套订阅
rxjs avoid nested subscription with 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}
);
确保你也知道 combine latest 和 fork join 之间的区别
我需要修复这个嵌套订阅,但我遇到了一些困难:-( 你能帮我找到解决办法吗?
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}
);
确保你也知道 combine latest 和 fork join 之间的区别