I have an array of objects as follows:
$scope.arr = [
{'val': true},
{'val': false},
{'val': false},
{'val': true},
{'val': false},
]
I am using ng-repeat
with a filter which sorts the array on the basis of the key 'val' and puts the objects with 'val' set to true before other objects. Here's the filter:
app.filter('ownerFirst', [function() {
return function(list) {
list.sort(function(a, b) {
return a['val'] - b['val'];
})
return list;
}
}])
template:
<div ng-repeat="obj in arr | ownerFirst">
But I am getting an infinite digest error. Why is this happening?
I don't think you need a custom filter, try using orderBy like this:
<div ng-repeat="obj in arr | orderBy: '-val'">
You'll need to put the -
-sign in front of val
because you want a descending sort.