Reputation: 31
I try to get data from ngrx selector as array using this code
categorys$ = this.store.select(getCategorysSelector)
but I just can get an object of store and I print the result in console and get this :
Store {actionsObserver: ActionsSubject, reducerManager: ReducerManager, source: Store, operator: ƒ}
hint : my data should be like this
1: {_id: '6294cbf9cdd093df47a24d01', name: 'asdasdasd', __v: 0} 2: {_id: '629730d1527c83ae22bc8c62', name: 'asdasd', __v: 0} 3: {_id: '6297311a527c83ae22bc8c65', name: 'asdasd', __v: 0} 4: {_id: '62973120527c83ae22bc8c67', name: 'asdasd', __v: 0}
so how i can get my data as array ???
Upvotes: 2
Views: 3864
Reputation: 574
this.store.subscribe(state=>{
this.getValue(state)
})
}
getValue(value:any){
this.permission = value.user.permission}
Upvotes: 0
Reputation: 99
categorys$ = this.store.select(getCategorysSelector)
will assign the Observable
you receive from the selector to your categorys$
variable.
In order to actually access the data within that selector you need to consume the Observable, either by subscribing to it via the async
pipe (https://angular.io/api/common/AsyncPipe) in your html code
<ng-container *ngFor="let category of categorys$ | async">
... do something here
</ng-container>
or by explicitly subscribing to your Observable within your ts code:
const categorySubscription = this.categorys$.subscribe(categories => {
// do something here
});
In case you directly subscribe in typescript, make sure to unsubscribe from your subscription OnDestroy
.
Upvotes: 2