首页 > 解决方案 > combineLatest 与 ngrx 未更新更改

问题描述

我有以下代码:

this._loadingStateSubscription = combineLatest(
      select(fromTreeSelector.selectLoadingState),
      select(fromFinanceSelector.selectLoadingState),
      (isTreeLoading, isFinanceLoading) => {
        return isTreeLoading && isFinanceLoading;
      }
    )
      .subscribe(isLoading => this.isLoading = !isLoading);

问题是,我的订阅没有更新更改。但下面我有这个代码

this.store.pipe(select(fromTreeSelector.selectLoadingState))
      .subscribe((isLoading) => {
        // this.isLoading = isLoading;
        console.log("isLoading", isLoading)
      });
    this._loadingStateSubscription = this.store.pipe(select(fromFinanceSelector.selectLoadingState))
      .subscribe((isLoading) => {
        // this.isLoading = isLoading;
        console.log("isLoading", isLoading)
      });

每次更新时我都会收到一条控制台日志消息。

两个选择器看起来像这样:

export const selectLoadingState = (state: AppState) => state.structures.isLoading;

对此有任何想法吗?

标签: javascriptangularngrx

解决方案


好的,我想通了:

this.store.select(fromTreeSelector.selectLoadingState),
this.store.select(fromFinanceSelector.selectLoadingState)

我必须添加this.store现在它正在工作。


推荐阅读