get ActivityList():any {
return this.activityList.snapshotChanges().map(changes => {
return changes.map(c => ({
key: c.payload.key, ...c.payload.val();
}));
});
}
getActivity() {
this.activityService.ActivityList.subscribe(activity => {
this.activity = activity;
});
}
<div *ngFor="let item of activity">
{{item.created|date:'medium'}}
</div>
这是我目前如何从Firebase RealTime数据库获取活动的方式。修改此内容以按created
值排序的最佳方法是在哪里以及如何进行。
答案 0 :(得分:1)
订阅后将其排序。
multi: true
答案 1 :(得分:1)
将服务更改为
get ActivityList():any {
return this.activityList.snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() })).sort((a, b) => b.created - a.created );
});
}