Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
30
rated 0 times [  33] [ 3]  / answers: 1 / hits: 24488  / 11 Years ago, wed, may 29, 2013, 12:00:00

I have an object that looks like this:



{
03 : Apple,
02 : Banana,
01 : Cranberry
}


and it orders it by the keys (which makes sense) in my ng-repeat. This results in the labels being out of alphabetical order (cranberry being first). How do I make it so that it orders my repeater by the values (alphabetically)?



I can supply it in the order I want to the ng-repeat, but it sorts it by the key. If I could make it not do that, then that would also work.


More From » sorting

 Answers
11

To sort array in ngRepeat you can use orderBy filter but it works only with arrays, so you should use array in ngRepeat.



It will be something like this in controller:



$scope.myData = [
{
key: 01,
value: Cranberry
},
{
key: 02,
value: Banana
},
{
key: 03,
value: Apple
}
];


and in html:



<div class=item ng-repeat=item in myData|orderBy:'value'>{{item.value}}</div>

[#77933] Tuesday, May 28, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rossj

Total Points: 606
Total Questions: 100
Total Answers: 116

Location: Dominican Republic
Member since Sun, Sep 4, 2022
2 Years ago
;