angular - 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
。
我在这里缺少什么?
谢谢
解决方案
推荐阅读
- docker - 从 docker hub 拉取 x509 证书错误
- python - 将带有项目列表的 dict 转换为 pandas 数据框
- python - 为什么当我返回 n 是浮点数的 int(n) 时,它仍然会返回浮点数?
- msbuild - 在几乎所有文件发生更改时打补丁
- python - 如何在 x 轴上排序箱线图类别
- python - 在新的 MSSQL 服务器上运行迁移时,出现以下错误
- powershell - 将过去 7 天的 windows 事件导出到 evt 文件
- javascript - 无法使用 jsPDF 下载 PDF
- json - 将复杂的结构转换为简单的 json
- python - 使用 twitterscraper 时如何使用 .txt 文件中的每个术语作为查询的一部分