首页 > 解决方案 > Ngrx 更改计数器状态不起作用我怎样才能使它起作用?

问题描述

我有一个看起来像这样的状态:

const initialState: AppState = {
    productsList: [],
    counter: 1
};

单击按钮时,我想将计数器增加 1。

这是我的减速机:

const _stateReducer = createReducer(
initialState,
on(updateProductCounterId, state=>{
debugger
return {
  ...state,
  counter: state.counter + 1
    }
 })
);

动作如下所示:

export const updateProductCounterId = createAction(
"[Product] Update Counter Id"
);

但是在减速器上,当我试图返回新状态时:

return {
  ...state,
  counter: state.counter + 1
    }

它不承认state.counter,只有state.productsList

我在这里缺少什么?

谢谢

标签: angularngrx

解决方案


推荐阅读