【发布时间】:2020-03-06 03:46:38
【问题描述】:
我想知道如何按日期对组件中数组中的数据进行排序,我有以下结构:
模板:
<div>
<button (click)="sortByDate()">
Sort by date
</button>
</div>
<div *ngFor="let rally of rallies$ | async">
<img src="{{ rally.icon }}" />
</div>
组件:
rallies$: Observable<Rally>;
constructor(private ralliesService: RalliesService) {}
ngOnInit() {
this.getRallies();
}
getRallies() {
this.rallies$ = this.ralliesService.getRallies();
}
sortRalliesByDate() {
???
}
问题是我明白了如何在订阅 observable 后使用组件中的数组进行操作,但现在我想直接在 observable 中操作并使用模板中的异步管道。
【问题讨论】:
标签: angular rxjs observable