为什么Async Pipe在模板中工作,但订阅在组件中不起作用?

时间:2017-12-29 05:59:39

标签: rxjs ngrx ngrx-store

我有一个带有应用主题配置的NgRx商店。当我在async

中使用navbar.component.html管道时
<div class="navbar" [style.background]="(theme | async).uiElements['navbar_background'].getColor()">

并从我的change-colors.component.ts更改导航栏背景颜色,一切正常。但是当我在navbar.component.ts

中订阅主题更改时
ngOnInit() {
    this.theme = this.themeStore.select('theme');

    this.themeSub = this.theme.subscribe(
      () => console.log('subs works')
    );
  }    

&#39; subs works&#39;文本没有出现在控制台中,i。即订阅不起作用。为什么会这样呢?

主题缩减器:

export function themeReducer(state = initialState, action: ThemeActions.ThemeActions) {
  switch (action.type) {
    case (ThemeActions.CHANGE_COLOR):    
      state.uiElements[action.payload.target] = new UiElement(
        state.uiElements[action.payload.target].name,
        action.payload.target,
        { R: action.payload.value.R, G: action.payload.value.G, B: action.payload.value.B }
      );

      return state;
    default:
      return state;
  }
}

0 个答案:

没有答案