本文介绍了可观察到的forkJoin不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在两个Observables上使用用户forkJoin.其中之一以流的形式开始...如果我直接订阅它们,则会收到响应,但forkJoin不会触发.有任何想法吗?
I'm trying to user forkJoin on two Observables. One of them starts as a stream... If I subscribe to them directly I get a response, forkJoin isn't firing though. Any ideas?
private data$: Observable<any[]>; private statuses$: Observable<any[]>; private queryStream = new Subject<string>(); .... this.data$ = this.queryStream .startWith('') .flatMap(queryInput => { this.query = queryInput return this._companyService.getCompanies(this.queryRequired + ' ' + this.query, this.page, this.sort); }) .share(); ... Observable.forkJoin(this.statuses$, thispanies$) .subscribe(res => { console.log('forkjoin'); this._countStatus(res[0], res[1]); }); // This shows arrays in the console... this.statuses$.subscribe(res => console.log(res)); thispanies$.subscribe(res => console.log(res)); // In the console Array[9] Array[6]推荐答案
forkJoin的一个非常普遍的问题是,它要求所有源Observable都发出至少一项,并且所有它们都必须完成.
A very common problem with forkJoin is that it requires all source Observables to emit at least one item and all of them have to complete.
换句话说,如果this.statuses$或thispanies$不发出任何项目,并且直到它们都完成forkJoin时才发出任何东西.
In other words if this.statuses$ or thispanies$ doesn't emit any item and until they both complete the forkJoin won't emit anything.
this.statuses$.subscribe( res => console.log(res), undefined, () => console.log('completed'), );更多推荐
可观察到的forkJoin不触发
发布评论