So i need help, trying to figure out my school project example about using NgRx with api services.
I'm getting error in ngrx selector createSelector(), cannot read property of undefined.
Here is StackBlitz : https://stackblitz.com/github/NikolaLukic1/ngrx-example
I guess i messed up something with reducers, or in app.module.ts
Your selector was not good. Firstly you have to check whether that state has property called 'posts' and then ask for it, it is a common issue these days.
Here you can find your stackBlitz updated and working.
The code you need is here:
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 : '';
}
);