Reputation: 4518
I have an array of objects matchedProfiles
and I'm trying to order those objects by a property's value in them.
matched profiles = [
{
common: Array[1],
match: 8.333333333333329,
score1: Array[1],
score2: Array[1],
user1ID: "1116145178404907",
user2ID: "1710007182568600"
},
{
common: Array[1],
match: 25,
score1: Array[1],
score2: Array[1],
user1ID: "170401213316838",
user2ID: "1710007182568600"
}
]
I tried to order this array
var sortedMP = $filter('orderBy')(matchedProfiles, match);
but I'm getting an error in the console log
Uncaught ReferenceError: match is not defined
Upvotes: 0
Views: 589
Reputation: 905
According to documentation https://docs.angularjs.org/api/ng/filter/orderBy you can pass expression as a string 'match'
var sortedMP = $filter('orderBy')(matchedProfiles, 'match');
or function
var sortedMP = $filter('orderBy')(matchedProfiles, function(profile) {
return profile.match;
});
Upvotes: 1
Reputation: 25352
Try like this
var sortedMP = $filter('orderBy')(matchedProfiles, 'match');
Upvotes: 1