仅使用一个还原器将我的错误与ngrx丢给我



我正在用商店在Angular上工作,由于某些Redux的错误,我无法构建项目。

实际上,使我的商店正常工作的唯一方法是使用此配置

app.module.ts- imports

StoreModule.forRoot({applicationState: AppReducer}),

app.reducer.ts

export function AppReducer(state = initialState, action: Action): AppState {
switch (action.type) {
    case types....:
      return {...state, ...};
...

在我的组件中

this.store.select(s => s.applicationState.myValue).subscribe()...

它不能正确地构建,但是当我服务两次时,我至少可以测试我的项目。由于我没有任何替代(我的AppState充满了数字,数组等,但没有替代),只有一个还原器,我不明白我应该如何在App.module.ts中声明我的ActionMapreDucer,以便能够订阅我这样的价值观:

this.store.select('myValue').subscribe(..)

我尝试了很多事情,研究了许多样本,但是我无法弄清楚如何解决该问题,因此我的项目无法构建:(。

,即使您只有一个还原器,也看来您没有重新分类也无法使用NGRX的商店。:(

这可以完成工作

index.ts

export interface State {
    state: AppState; // contains my store, real 'state'
}
export const reducers: ActionReducerMap<State> = { // State isnt my 'real' state !
  state: AppReducer
};
export const getValueState = createFeatureSelector<AppState>('state')
export const getValue = createSelector(getValueState, (state: AppState) => state.value);

app.moduls.ts- imports

StoreModule.forRoot(reducers)

component.ts

this.store.select(getValue).subscribe(...);

我仍然无法弄清楚为什么我不能使用select('myValue')这样的选择器...但是现在很好。

最新更新