I have an array of objects...
var userObjects =[
{userName: bob,
age: "25",
gender: "m"
},
{userName: bill,
age: "15",
gender: "m"
},
{userName: jen,
age: "45",
gender: "f"
},
]
Now I have an ng-repeat in my HTML to iterate over this array of objects. I want it to sort the age:
<tr ng-repeat="user in userObjects | orderBy:-age">
In my JS I am converting my ages to intergers....
data.forEach(function(user){
user.age= parseFloat(user.age);
}
Angular will not sort by age, I would expect to see...
bill, 15
bob, 25
jen, 45
But instead they are all over the place. What am I doing wrong?
Thanks!
Try wrapping -age
in single quotes, like '-age'
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