angular - 无法使用带有ngrx的角度读取未定义的属性“地图”
问题描述
我需要帮助来理解当我尝试使用来自 store 的 Observable 数组时发生的这个错误。
这是控制台错误
ERROR TypeError: Cannot read property 'map' of undefined
at ngrx-entity.js:67
at ngrx-store.js:1198
at memoized (ngrx-store.js:1039)
at defaultStateFn (ngrx-store.js:1079)
at ngrx-store.js:1207
at memoized (ngrx-store.js:1039)
at ngrx-store.js:1198
at memoized (ngrx-store.js:1039)
at defaultStateFn (ngrx-store.js:1079)
at ngrx-store.js:1207
这是我进行调度并尝试使用 Observable 的地方
template: `
<bc-patient-search> </bc-patient-search>
<ngx-spinner [fullScreen]="false"></ngx-spinner>
<bc-patient-preview-list [patients]="vm$ | async">
</bc-patient-preview-list>
`,
})
export class FindPatientPageComponent {
patients$: Observable<Patient[]>;
vm$ : Observable<Patient[]>;
constructor(
private store: Store<fromPatients.PatientsState>,
private apiPatientService: ApiPatientsService,
private spinner: NgxSpinnerService
) {
this.vm$ = store.pipe(select(fromPatients.selectPatientsTotal));
}
ngOnInit() {
this.spinner.show();
this.patients$ = this.apiPatientService.searchPatientList();
this.loadPatients();
setTimeout(() => {
this.spinner.hide();
}, 2000);
}
loadPatients() {
this.store.dispatch(PatientLoadActions.loadPatients());
}
}
这是选择器
export const selectPatientsTotal = createSelector(
selectAllPatients,
patients => patients.filter(patients => patients != null && patients != undefined)
);
export const selectAllPatients = createSelector(
selectPatientState,
fromPatients.selectAll
);
和减速机
on(PatientLoadActions.loadPatientsSuccess, (state, action) =>
adapter.setAll(action.patients, state)
),
解决方案
是特色商店吗?然后你需要创建你的基本特征选择器:
export const selectPatientsState = createFeatureSelector(patientsFeatureKey);
比较https://ngrx.io/guide/entity/adapter,最后一个代码片段 (index.ts)。我想我记得我第一次使用 ngrx 实体时的相同错误。
推荐阅读
- c - hiredis 使用 TLS 失败
- mysql - 如何减去和除以不同日期的 3 个子查询?
- c# - ANTLR 访问者单元测试在一条规则上成功,但在另一条规则上失败
- sql-server - 变量值可以传递给局部变量吗?然后可以使用本地变量来构建动态 SQL 查询吗?
- python - 如何更改可选函数参数的默认值
- python-3.x - 尝试使用循环顺序抓取多个页面以更改 url
- html - 使用 css 定位与其他东西具有相同类的东西
- ms-access-2007 - 访问表中的回车
- mysql - 使用 UNION 的大型复杂查询允许我按 ORDER BY 但不允许 GROUP - 为什么?
- javascript - 如何触发浏览器密码保存