Say I have 4 item in ng-repeat
. How can I exclude one item in orderBy
?
<li ng-repeat="item in items | orderBy:'id':true">
$scope.items = [
{"name":"item1","id":1},
{"name":"item2","id":2},
{"name":"item3","id":3},
{"name":"item4","id":4}
];
How can I make, say, id:3 always appear as the first item?
plunker demo
You can create a function to alter the value you sort by (plunker):
$scope.itemSortValue = function(item) {
if (item.id == 3)
return -1;
return item.id;
}
Html:
<li ng-repeat="item in items | orderBy:itemSortValue">
{{item.name}}
</li>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With