【发布时间】:2019-01-25 18:02:58
【问题描述】:
如何在 ngrx 实体中初始化状态时为实体设置默认值?
potato.model.ts
export class Potato {
id: number;
weight: number;
}
potato.reducer.ts
export interface PotatoState extends EntityState<Potato> { }
export const potatoAdapter: EntityAdapter<Potato> = createEntityAdapter<Potato>();
const potatoesInitialState: PotatoState = potatoAdapter.getInitialState();
export const initialState: State = {
potatoes: potatoesInitialState
};
export function reducer(state = initialState, action: PotatoActions): State {
switch (action.type) {
// ...
}
}
例如我需要设置默认权重 0.2。
【问题讨论】:
标签: angular typescript ngrx ngrx-entity