I need help to understand this error that happens when I try to use an Observable array that comes from store.
this is the console error
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
here is where I make the dispatch and try to use the 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());
}
}
here is selector
export const selectPatientsTotal = createSelector(
selectAllPatients,
patients => patients.filter(patients => patients != null && patients != undefined)
);
export const selectAllPatients = createSelector(
selectPatientState,
fromPatients.selectAll
);
and reducer
on(PatientLoadActions.loadPatientsSuccess, (state, action) =>
adapter.setAll(action.patients, state)
),