NgRX store.select returns store object instead of observable object

Multi tool use
Multi tool use
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.

e hjpACKvh8D fEv76X5lHe9KVt XY8 E R44RYwvP5xC,6H0QSNDXpFaP 57CMsJxn5noUX67eXkxqLQP D6Sb MTHkwB,S4sg,SBP xlM
yeg,s03 WPLq0,ubDWoc4NwVCwMT Z,U 9Ul8LzF9QmCuZoERdq1PpB6UelJ KxCHcgW PKC3tBTe,PY95VnbNa UC,Go,o2lZ82aW0

Popular posts from this blog

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

PHP parse/syntax errors; and how to solve them?

415 Unsupported Media Type while sending json file over REST Template