If you add order by you will receive an error:
orderBy:notarray
Value is not array-like
Luckily angular error reference manual will provide following suggestion:
orderBy must be used with an array-like value so a subset of items can
be returned. The array can be initialized asynchronously and therefore
null or undefined won't throw this error.
To use orderBy to order the properties of an object, you can create
your own array based on that object:
$scope.arrFromMyObj = Object.keys(myObj).map(function(key) {
return myObj[key]; }); });
Full code:
<html ng-app="SoApp">
<head>
</head>
<body>
<table ng-controller="appCtrl">
<tr ng-repeat="value in data| orderBy:'createdAt':true" >
<td>{{value.createdAt}}</td>
</tr>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script>
angular.module('SoApp', [])
.controller('appCtrl', ['$scope',
function($scope) {
$scope.objs = {
"1" : {name:'abc',createdAt:'2016-06-25'},
"4" : {name:'abc',createdAt:'2015-07-06'},
"7" : {name:'abc',createdAt:'2015-03-12'},
"2" : {name:'abc',createdAt:'2016-01-04'},
"6" : {name:'abc',createdAt:'2016-06-17'}
};
$scope.data = Object.keys($scope.objs).map(function (key) {return $scope.objs[key]});
console.log($scope.arrFromMyObj )
}]);
</script>
</body>
</html>
ng-repeat="obj in objs track by $index | orderBy : '-createdAt' "ng-repeat="obj in objs | orderBy:'-createdAt'"