如何按时间在角度ngfor中进行数据排序

问题描述 投票:0回答:2

我有主题名称和时间,如何按时间排序主题,谢谢任何人帮助我

<tr *ngFor="let days of DaysList">
      <th class=" text-white bg-success2">{{ days.DayName }}</th>
      <td *ngFor="let subjects of filterItemsOfType(data.SubjectInfo,days.DayName)"><button  (click)="deleteConfirm(data._id,subjects._id)" type="button"
          class="btn btn-primary  btn-block btn-sm"> {{subjects._id.SubjectName}}{{subjects.Time}}</button></td>


    </tr>

附在图像下方

enter image description here

angular angular6 angular7 angular8
2个回答
0
投票
您可以使用类似本文的自定义orderby / sortby管道:

Sort/Orderby pipe


0
投票
这里是如何按角度排序的示例:

https://stackoverflow.com/a/46604776/6133565

不要使用管道...

您可以尝试这样的事情:

ngOnInit() { this.sortedItems = items.sort((a: any, b: any) => new Date(a.date).getTime() - new Date(b.date).getTime() ); }

© www.soinside.com 2019 - 2024. All rights reserved.