如何更新NGRX中实体的选择ID

问题描述 投票:0回答:1

我有下面的代码,并且每当用户选择一个实体时,我要更新selectedScenarioID。在ngrx存储中,属性会更新。

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

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

angular ngrx
1个回答
0
投票

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

总之,您调度一个动作,然后在化简器中对状态进行突变。


export const reducer = createReducer(
  initialState,
  on(ViewBookPageActions.selectBook, (state, { id }) => ({
    ...state,
    selectedBookId: id,
  }))
);
© www.soinside.com 2019 - 2024. All rights reserved.