Yes, the custom filter is a separate module and you can write it as:
iApp.filter('myfilter', function() {
return function( items, types) {
var filtered = [];
var looping = function(name){
angular.forEach(items, function(item) {
if(item.type === name){
filtered.push(item);
}
});
}
if(types.car == true){
looping('CAR');
}
if(types.bike == true){
looping('BIKE');
}
if(types.cycle == true){
looping('CYCLE');
}
return filtered;
};
});
Controller:
$scope.types = {car: false, bike:false, cycle: false};
$scope.items = [
{name: 'bmw', type:'CAR' },
{name: 'ducati',type:'BIKE'},
{name: 'airbas',type:'CYCLE' }
];
Demo 1 Plunker
[EDIT]
If you want to show all cells when no checkbox is selected, add this to filter:
var flag = true;
angular.forEach(types, function(type){
flag = flag & !type; // if one of flags will be false, we get flag=false
});
if(flag == true){
return items;
}
Demo 2 Plunker
FYI: You can see that filters do not use $scope
. If you want to pass additional argument the syntax should be:
<tr ng-repeat="item in items | filter:myfilter:types">
where types
is some object