簡體   English   中英

rxjs在combineLatest中調用combineLatest

[英]rxjs call combineLatest in combineLatest

我遇到了rxjscombineLatest方法的問題。 我想打電話給combineLatestcombineLatest和它不工作,雖然它返回可觀察對象。 請幫忙解決問題。 從不調用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 '';
    }
);

已解決:沒有任何訂閱者它不起作用,所以我不得不訂閱它

combineLatest()運算符在其所有源Observable發出至少一個值時發出一個值。

因此,如果console.log(...)從不打印它意味着this.search$this.services$永遠不會發出任何內容。 換句話說,這意味着store.select('currentRegions')store.select('services')store.select('search')永遠不會發出任何值。

請注意,您可以使用startWith() (即使使用startWith(null) )。

這有效: https//jsbin.com/gecede/2/edit?js,console

這不起作用: https//jsbin.com/livafar/2/edit?js,console

RxJS CombineLatest是一種AngularJS $ q.all

import 'rxjs/add/observable/combineLatest';


Observable
      .combineLatest(this.store.select('currentRegions'), this.store.select('services')
      .do(console.log)
      .subscribe();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM