@ngrx/store select - 如何将 Observable<Array<StaffInterface>> 转换为 Array<StaffInterface>

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

试图从 ngrx store.select 中的 Observable<Array<StaffInterface>> 获得 Array<StaffInterface>,其中 returns Observable<Array<StaffInterface>> 这样我就可以通过 Array<StaffInterface>到 primeng 数据表。

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

在上面的赋值中store.selectreturnsObservable<Array<StaffInterface>>。我需要将其转换为 Array<StaffInterface>

你应该 subscribing 到值然后 return 数组如下

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

在模板中使用异步管道。

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

最后,我将代码更改为 store.select 以将 Store Observable 数据存储到 staffList$: Observable 并按照@Brendan 的指示在模板中使用 async 管道。

类型之间不需要转换。

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

在 HTML 模板中:

{{staffList$ | async}}