I have an array I have sorted with the Angular orderBy command in my html. I need to retrieve the items in the list in the order in which they are sorted. Is there a way to do this?
using $scope.people[] ng-repeat makes a table as follows:
Original
id name
2 bob
4 joe
1 dave
After sorting I get
id name
1 dave
2 bob
4 joe
Now I want to be able to access $scope.people[] but in the sorted order. Is this possible?
Angular 1.3.x added "alias" expression which will store the intermediate results of the repeater after the filters have been applied.
<div ng-repeat='p in people | orderBy : "name" as result'>
{{p.name}}
</div>
<p> <b>Original</b></p>
<div>{{people || json}}</div>
<p><b>Sorted</b></p>
<div>{{result || json }}</div>
Plunkr
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