0

I am tying to filter my table by using checkboxes, I succeed doning this with radio buttons with the following code:

<label class="checkbox-inline" >
       <input type="radio" ng-model="term" value="HT1"/> HT1
       <input type="radio" ng-model="term" value="HT2"/> HT2
       <input type="radio" ng-model="term" value="VT1"/> VT1
       <input type="radio" ng-model="term" value="VT2"/> VT2
</label>
<tr ng-repeat="course in vm.courses|filter:term">

I realize that the same no not work when using checkboxes because all checkboxes gets the same ng-model. But how do I do this with checkboxes? I would like to use javascript and not angular if I have to use a script

sacan
  • 47
  • 7
  • 1
    I think you can create an angular filter (http://stackoverflow.com/questions/16227325/how-do-i-call-an-angular-js-filter-with-multiple-arguments) with arguments. You can bind checkbox with different ng-model and put it into your filter to customize filter. – Silvinus May 31 '16 at 13:14

1 Answers1

2

try this :

<input type="checkbox" ng-model='filter1' ng-true-value="'filter1'" ng-false-value=''/> filter1
<input type="checkbox" ng-model='filter2' ng-true-value="'filter2'" ng-false-value=''/> filter2
<tr ng-repeat="course in vm.courses | filter:filter1 | filter:filter2">

or write a custom filter:

app.filter('myCustomFilter', function() {
return function(input, optional1,optional2) {
     var output;
     // Do filter work here
     return output;
    }
});

and use it the following:

<tr ng-repeat="course in vm.courses | myCustomFilter">
othman.Da
  • 621
  • 4
  • 16