I've been looking for severeal days how to create a dynamic filter with multiple checkboxes in AngularJS easily and none of the solutions I found satisfied me.
Here is an example of a filter that will display everything when the checkboxes are unchecked and filter the data when checkboxes are checked. (Good for search engine to look for a hotel with wifi, balcony... for example)
Filter :
app.filter('conveniences_filter', function() { return function( items, types) { var filtered = []; var displayItem; angular.forEach(items, function(item) { displayItem = true; angular.forEach(types, function(type, key) { if(type == true && item[key] == false) { displayItem = false; } }); if(displayItem == true) { filtered.push(item); } }); return filtered; }; });
In your controller :
$scope.types = {wifi: false, balcony: false}
In your HTML
ng-repeat="property in properties | conveniences_filter:types"
Important : Your keys in your $scope.types have to be the same as your key in your properties items or it's not gonna work.
Example of a property here :
Object { name: property, wifi: false, balcony: true }
I hope it's gonna be useful :)