你如何使用orderBy
过滤器来反转日期数组?我可以.sort().reverse()
在模型本身上使用,但如果可能的话,我宁愿让 angular 来做
JS
var myApp = angular.module('myApp', []);
myApp.controller('DatesCtrl', ['$scope', function($scope) {
$scope.dates = [ new Date(2013, 0, 1), new Date(2013, 1, 1) ];
}]);
HTML
<div ng-controller="DatesCtrl">
<div ng-repeat="d in dates" ng-bind="d | date:'medium'"></div>
</div>
预期结果
2013 年 2 月 1 日 12:00:00 AM 2013 年
1 月 1 日 12:00:00 AM
根据文档,我希望能够这样做,但它没有用
<div ng-controller="DatesCtrl">
<div ng-repeat="d in dates | orderBy:'d':true" ng-bind="d | date:'medium'"></div>
</div>