【发布时间】:2017-05-04 15:10:28
【问题描述】:
sort 来自Observable 的项目列表的最佳方法是什么,并且仍然可以使用async pipe? (我读到制作自定义排序管道并不是很有效。)我想避免订阅和保留数据的本地副本,因此只使用异步管道......
//can I use map here and filter items right in the observable and get rid of subscribe?
this.test$ = Observable.of(['one', 'two', 'three'])
.subscribe((data) => {
data.sort((a, b) => {
return a < b ? -1 : 1;
});
this.data = data;
});
模板:
<div *ngFor='let item of data'>
<!-- want to be able to use async pipe here -->
【问题讨论】: