-1

I have a list of checkboxs:

 <input type="checkbox" ng-model="myFilter.filterField" ng-true-value="'value1'" ng-false-value="''"> value1<br>
 <input type="checkbox" ng-model="myFilter.filterField" ng-true-value="'value2'" ng-false-value="''"> value2<br>

.... .... And I want to filter the checked checkboxes fields like this:

x in X | filter: { 'filterField': ['value1','value2']}

Any solution to push into my array filterField and filter more than one value? Thanks!

Charly
  • 166
  • 14

3 Answers3

0

It is better to use custom filters in that case

$scope.filterField = function(x) {
    return x.filterField == 'value1' || x.filterField == 'value2' || x.anotherField == 'value';
};


x in X | filter: filterField
Suresh Gogu
  • 359
  • 5
  • 12
0

From AngularJS : Custom filters and ng-repeat

Checking multiple fields

// Filter, where element would be your x
$scope.filterFn = function(element)
{ 
    if(element.field === 'value1' || element.anotherField === 'value2')
    {
        return true; // this will be listed in the results
    }
    return false; // otherwise it won't be within the results
};

And then apply it
x in X | filter:filterFn

Community
  • 1
  • 1
taguenizy
  • 2,140
  • 1
  • 8
  • 26
0

Another way would be to use one custom filter and add parameters to it. This fiddle shows how to work with a filter with multiple parameters: http://jsfiddle.net/halirgb/Lvc0u55v/

Like this

myApp.filter('customFilter', function() { // Name of filter
return function(first, second,third) {
// write filter code here
  return second;// shows the last filter parameter
};});

And use the filter like this:

  <div ng-repeat="x in X">  {{x|customFilter:myFilter.filterField}} </div>
Plemo
  • 51
  • 5