【问题标题】:How to update the Select ID of the entity in NGRX如何在 NGRX 中更新实体的 Select ID
【发布时间】:2019-10-30 01:26:43
【问题描述】:

我有下面的代码,我想在每次用户选择 ngrx 商店中更新的实体之一时更新 selectedScenarioID。

export interface IScenarioState extends EntityState<ScenarioState> {
  selectedScenarioId: string | number | null;
}

export const initialState: IScenarioState = fromAdapter.adapter.getInitialState({
  selectedScenarioId: '00001'
});

【问题讨论】:

    标签: angular ngrx


    【解决方案1】:

    看看NgRx Example App,我们有完全相同的用例。

    简而言之,您调度一个动作并在减速器中改变状态。

    
    export const reducer = createReducer(
      initialState,
      on(ViewBookPageActions.selectBook, (state, { id }) => ({
        ...state,
        selectedBookId: id,
      }))
    );
    

    【讨论】:

      猜你喜欢
      • 2020-09-25
      • 1970-01-01
      • 2015-09-26
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多