我有一个关于rxjs和combineLatest方法的问题。我试图在combineLatest中调用combineLatest,虽然它返回了Observable对象,但它不起作用。请帮忙解决这个问题。永远不会调用console.log
实际上,所有观察者都在不同的文件中,所以我不能将this.search$移到this.services$
this.search$ = store.select('search');
this.services$ = Observable.combineLatest(
store.select('currentRegions'),
store.select('services'),
(regions, services) => {
// some filter here
return services;
}
);
this.autocomplete$ = Observable.combineLatest(
this.search$,
this.services$,
(search, services) => {
console.log('show me, please');
return '';
}
);已解决:如果没有订阅者,它将无法工作,所以我必须订阅它
发布于 2017-02-08 19:29:29
当combineLatest()运算符的所有源可观测对象都至少发出一个值时,它就会发出一个值。
因此,如果console.log(...)从不打印,这意味着this.search$或this.services$永远不会输出任何内容。换句话说,这意味着store.select('currentRegions')、store.select('services')或store.select('search')中的一个永远不会发出任何值。
请注意,您可以使用startWith() (即使使用startWith(null))。
发布于 2017-07-04 19:04:18
RxJS CombineLatest是一种AngularJS $q.all
import 'rxjs/add/observable/combineLatest';
Observable
.combineLatest(this.store.select('currentRegions'), this.store.select('services')
.do(console.log)
.subscribe();https://stackoverflow.com/questions/42111759
复制相似问题