NgRx: Get data from store but it's undefined
I found out
I looked that how else I can make a request my data from store. I found one way, in context of my app it looks like:
this.store.select(state => state).subscribe(data => { console.log('data', data);});
And I get in console the object:
{ message: { Products: Array[3], loading: false } }
What does this message mean? I made a global search and saw that I implemented my reducer in app.module.ts
as:
StoreModule.forRoot({ message: ProductReducer }),
So I created a index.ts
in reducers folder and export a reducer bellow:
import { ActionReducerMap } from '@ngrx/store';import * as fromProducts from './products.reducer';export interface AppState { products: fromProducts.ProductState;}export const reducers: ActionReducerMap<AppState> = { products: fromProducts.productsReducer};
And now in app.module.ts
it imports as:
StoreModule.forRoot(reducers),
and now this code is working well:
this.store.select(getProducts).subscribe(products => { console.log('products', products);});