Angularjs groupBy + orderBy

后端 未结 5 1752
暗喜
暗喜 2020-12-07 01:01

I am using groupBy from angular-filter to group an array of objects by their date property.

5条回答
  •  甜味超标
    2020-12-07 01:57

    We can achieve this by ordering the data in controller & converting groupBy output to Array.

    In controller, order the records before sending it to view :

    $scope.events = $filter('orderBy')(events, '-date');
    

    Now the template, receives data in sorted order. After grouping, we need to transform it to Array :

    {{ day | dayEvents[0].date: mediumDate }}

提交回复
热议问题