什么是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;
});
Run Code Online (Sandbox Code Playgroud)
模板:
<div *ngFor='let item of data'>
<!-- want to be able to use async pipe here -->
Run Code Online (Sandbox Code Playgroud)