【发布时间】:2021-04-24 06:08:25
【问题描述】:
我有几种方法
getFirstDataBunch() {
return this.repository.getData(this.parameter).pipe(
switchMap(
result => {
//Do something with result;
return of(true);
}
)
);
}
然后我打电话给我的ngOnInit:
function ngOnInit(){
forkJoin(this.getFirstDataBunch(), this.getSecondDataBunch(), this.getThirdDataBunch()).subscribe(
results => {
//do stuff with results;
}
);
}
我可以看到所有的 observable 都被调用了,它们返回一个 observable,但是 forkJoin 订阅方法从未被调用,从我读到的 forkJoin 仅在所有 observable 返回并完成时才会触发,而且我确实相信是这样,那为什么不开除呢?
我还看到有些人只是选择combineLatest,但因为这些方法只会在我真的不需要继续寻找更新时才返回。
【问题讨论】:
-
显然,至少有一个
dataBunch()流没有完成。你检查了吗? -
@mbojko 我该怎么做?函数与您在此处看到的完全一样,我对一些数据进行 GET 请求,进行一些转换,然后返回一个 observable of(true),这样 switchMap 确实有一个返回类型 Observable。
标签: angular rxjs observable