1

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>

4

3 回答 3

3

在模板中使用异步管道。

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

于 2017-12-12T06:01:57.657 回答
1

你应该是subscribing值,然后返回数组如下

this.staffList = store.select(staffList)
                          .subscribe(staffList => staffList);
于 2017-12-12T06:01:43.280 回答
0

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

类型之间不需要转换。

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

在 HTML 模板中:

{{staffList$ | async}}
于 2017-12-13T06:25:00.593 回答