Reputation: 47
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
Upvotes: 0
Views: 221
Reputation: 631
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">
Upvotes: 2