@ngrx/store select - How to convert Observable<Array<StaffInterface>> to Array<StaffInterface>

3.3k Views Asked by At

tying to get Array<StaffInterface> from a Observable<Array<StaffInterface>> in ngrx store.select which returns the Observable<Array<StaffInterface>> so that i can pass the Array<StaffInterface> to primeng datatable.

staffList: Array<StaffInterface>; 
this.staffList = store.select(staffList);

In the above assignment store.select returns Observable<Array<StaffInterface>>. I need to convert it to Array<StaffInterface>

3

There are 3 best solutions below

0
On BEST ANSWER

Use the async pipe in your template.

https://angular.io/api/common/AsyncPipe

0
On

finally, i changed my code to store.select to get the Store Observable data to staffList$: Observable and used async pipe in the template as told by @Brendan.

No conversion was needed between types.

staffList$: Array<StaffInterface>; 
this.staffList$ = store.select(staffList);

in HTML template:

{{staffList$ | async}}
0
On

You should be subscribing to the value and then return the array as below

this.staffList = store.select(staffList)
                          .subscribe(staffList => staffList);