NgRX store.select returns store object instead of observable object

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


NgRX store.select returns store object instead of observable object



I have written a short example of Ngrx. I had no idea why this short code could not run properly.


constructor(private store: Store<CounterState>){
this.counter = store.select('counter');
console.log(this.counter);
}



This piece of code prints a Store object to the console instead of an observable. It is weird.
The full version of the app please follow the link below.
https://stackblitz.com/edit/angular-dq7ssf





Recently with the appearance of rxjs v6, do something like this this.counter = store.pipe(select('counter')); Also check demo app on the repo on github for more inside. thanks
– The Oracle
yesterday




2 Answers
2



In the example you posted you're defining the rootstate with:


StoreModule.forRoot({ counterReducer })



Meaning that counterReducer is the key to access your counter state, to solve this you can select the counter as follows


counterReducer


this.counter = store.select('counterReducer', 'counter');



Or you could give your reducer a key:


StoreModule.forRoot({ counter: counterReducer });
this.counter = store.select('counter', 'counter');



Well, if you have a look at the Ngrx Store Source, Store is an Observable!


Store


Observable


export class Store<T> extends Observable<T> implements Observer<Action> {
...
}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

CRM reporting Extension - SSRS instance is blank

Keycloak server returning user_not_found error when user is already imported with LDAP