I'm trying to make a filter inside a ng-repeat based on a custom filter that receives two parameters. At the same time, one of those parameters is one property of the object on the repeat.
So in my ng-repeat code I have:
<tr ng-repeat="player in myTeam | bitwiseAnd:{firstNumber: player.Flag, secondNumber: type}">
But it's not working. If I debug it, the filter is receiving in the first parameter undefined.
I've read the documentation :
I've read also multiple related questions in SO
- Filtering by Multiple Specific Model Properties in AngularJS (in OR relationship)
- Passing arguments to angularjs filters
- How do I call an Angular.js filter with multiple arguments?
Without success.
I've created a plunker where we can see how the filter is working properly when I use it as an expression, so probably the problem is sending the values inside the ng-repeat statement.
Here is the plunker:
Thanks for your time
I'm trying to make a filter inside a ng-repeat based on a custom filter that receives two parameters. At the same time, one of those parameters is one property of the object on the repeat.
So in my ng-repeat code I have:
<tr ng-repeat="player in myTeam | bitwiseAnd:{firstNumber: player.Flag, secondNumber: type}">
But it's not working. If I debug it, the filter is receiving in the first parameter undefined.
I've read the documentation : https://docs.angularjs/guide/filter
I've read also multiple related questions in SO
- Filtering by Multiple Specific Model Properties in AngularJS (in OR relationship)
- Passing arguments to angularjs filters
- How do I call an Angular.js filter with multiple arguments?
Without success.
I've created a plunker where we can see how the filter is working properly when I use it as an expression, so probably the problem is sending the values inside the ng-repeat statement.
Here is the plunker: http://plnkr.co/edit/IGvDBq?p=preview
Thanks for your time
Share edited May 23, 2017 at 12:19 CommunityBot 11 silver badge asked Aug 28, 2014 at 15:33 Mario LevreroMario Levrero 3,3774 gold badges27 silver badges59 bronze badges2 Answers
Reset to default 3myTeam | bitwiseAnd
applies the bitwise
filter to the team
array as a whole, not the players. So the effect is like writing
<tr ng-repeat="player in true">
if the filter returns true. What you want is a filter that returns an array. You can create your own filter or use the filterfilter. The latter one is tricky to bine with yours, but it's possible. At first you define a predicate function in your controller
$scope.bitwiseAnd = function(type) {
return function(player) {
return $filter('bitwiseAnd')(player.Flag, type);
}
}
That function applies your bitwiseAnd
filter and is itself applied on every player. Then you use the filterfilter with that function:
<tr ng-repeat="player in myTeam | filter:bitwiseAnd(type)>
Working Plunker
As the purpose is to display the users who pass the filter with 'true' value, below code can help:
<tr ng-repeat="player in myTeam" ng-if="player.Flag|bitwiseAnd:type">