I am new to angular2, currently, I am working on a project which using @ngrx/store and subscribe classes. I am confused on map method is not working while subscribe store is working. Please help me in understanding when to use map and subscribe method. The code is below.
this.store.select('rating').subscribe(({ topPicks }) => { // code is working });
this.store.select('rating').map(({ topPicks }) => // not working);
From what I understand, here
this.store.select('rating')
is an Observable. Depends on whether the observable is Hot or Cold, (For more information read this blog) observable will start emitting values. In your case, first statement works because you are subscribing to observable.Map
is just an operator which you can use it on the values emitted by an observable(its does not work as subscriber).Second statement does not work as there is no subscriber to the Observable. To use map operator, you can do like below:
To know more about operators, you can have a look at documentation.