Reputation: 75
I'm using angular and ng-repeat to iterate over data. I want to show only items where purchased-used <=5, but it is showing 5, 4, 55, 3, 33, 2, etc., as the result set where it should only show 5,4,3,2.
$scope.users = [{
first_name: 'Richard',
last_name: 'Grayson',
purchased: 50,
used: 10,
},
{
first_name: 'Donna',
last_name: 'Troy',
purchased: 6,
used: 3,
}]
And then on the page:
<tr ng-repeat="user in users | filter:user.purchased-user.used<=5:true">
Dick should not show in the list, but Donna should. They both show up though.
I know I could write a function for the filter, but this seems like such a simple comparison that I shouldn't have to. It seems like it should work, but there's something I'm missing.
Thanks!
Upvotes: 0
Views: 273
Reputation: 746
You just have to make a custom filter:
$scope.customFilter = function(user){
return user.purchased-user.used <= 5;
};
And call it from your repeater:
<tr ng-repeat="user in users | filter: customFilter">
Upvotes: 0