我有初始状态
export const initialState: State = {
activeStep: 0
};
和减速器
export function reducer(
state: State = initialState,
action: SignUpActions
): State {
switch (action.type) {
case SignUpActionType.SET_ACTIVE_STEP:
return {
...state,
activeStep: action.payload
};
}
}
实际上,我触发了一项更改状态数据的操作,如下所示:
@Effect()
error$ = this.actions$.pipe(
ofType<Error>(SignUpActionType.ERROR),
switchMap((action) => this.responseErrorDialog(action.payload)),
map((res) => {
return new SetActiveStep(0);
})
);
并在此零件上订阅将其存储在组件中
this.store.pipe(select(getActiveStep)).subscribe((step: number) => {
if (step) {
...do some stuff
}
});
问题是组件中的订阅不会对变量的更改做出反应
我认为,因为国家的新价值等于上一步,但我需要对商店的每次变更做出反应
我该怎么做?
答案 0 :(得分:0)
活动步骤仍为0
-如果状态保持不变(因为已被记忆),则选择器将不会执行-请参见NgRx docs。
Alex Okrushko在去年NgRx: Selectors are more powerful than you think
上对这个概念以及如何根据您的需求进行了调整。