0

My question is very simple. I have an ngRepeat with filter, I want to apply many filters for the same key. For example, I want to filter all the players with names ' john ' and ' mickle '.

<tr ng-repeat="player in players | filter:{NAME:['john','mickle']}">
        <td>{{player.id}}</td>
        <td>{{player.name}}</td>
        <td>{{player.age}}</td>
 </tr>

For achieving this I have done like below, but it's not working.

    <tr ng-repeat="player in players | filter:query">
                <td>{{player.id}}</td>
                <td>{{player.name}}</td>
                <td>{{player.age}}</td>
    </tr>

And in the controller I wrote,

var filter_input_dict = {"NAME":['john','mickle']}
$scope.query = filter_input_dict;

Any help would be greatly appreciated.

Midhun KM
  • 1,647
  • 1
  • 21
  • 31
Sakeer
  • 1,885
  • 3
  • 24
  • 43
  • ng-repeat is missing a closing quote. Try changing "NAME" to "name" so that the case matches. – Michael Kang Aug 05 '14 at 07:16
  • 1
    also please have look here http://stackoverflow.com/questions/15868248/how-to-filter-multiple-values-or-operation-in-angularjs – Midhun KM Aug 05 '14 at 07:18
  • its not about the case match..i have updated my question please have a look – Sakeer Aug 05 '14 at 07:18
  • fix the unterminated string? – Michael Kang Aug 05 '14 at 07:19
  • i have changed to single quotes..but no use the result is still same. I have updated the question too – Sakeer Aug 05 '14 at 07:22
  • javascript properties are case-sensitive, you can't use "NAME" and 'name' and expect your filter to work. Also, passing an array as a property value, and expecting it to filter with a logical "OR" is incorrect. – Michael Kang Aug 05 '14 at 07:36

1 Answers1

0

You can do in the following way.

$scope.query = function(arr){return ['john','mickle'].indexOf(arr.name) > -1;};

Manaf P M
  • 453
  • 1
  • 5
  • 13