因此,我需要帮助,试图弄清有关将NgRx与api服务一起使用的学校项目示例。
我在ngrx选择器createSelector()中遇到错误,无法读取未定义的属性。
这是StackBlitz:https ://stackblitz.com/github/NikolaLukic1/ngrx-example
我想我用reducers或app.module.ts弄乱了东西
您的选择器不好。首先,您必须检查该州是否具有称为“职位”的财产,然后要求它,这是当今的普遍问题。
在这里,您可以找到您的stackBlitz更新并正在工作。
您需要的代码在这里:
import { createSelector } from '@ngrx/store';
const selectPosts = (state: any) => state.hasOwnProperty('posts') ? state.posts : '';
export const selectedPosts = createSelector(
selectPosts,
(state: any) => {
return state.hasOwnProperty('posts') ? state.posts : '';
}
);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句