Sort by date Angular 2 pipe

后端 未结 3 1348
梦如初夏
梦如初夏 2020-12-21 15:33

Here is my code:

{{conv.date | date: \'dd/MM/yyyy | j\'}} - {{conv
3条回答
  •  清歌不尽
    2020-12-21 16:20

    It is strongly suggested not to use such pipes according to Angular Documentation. See https://angular.io/guide/pipes#appendix-no-filterpipe-or-orderbypipe

    You can try something like this:

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

提交回复
热议问题