It is possible to remove filter using a checkbox?
If checkboxes are checked, filters inside ng-repeat would be disabled. For example, if the checkboxes countryfilter and winetypefilter are checked, the related filters would be disabled.
Original code (filters enabled)
<li ng-repeat="wine in wines | winetypefilter:winetypes| countryfilter:countrytypes | stylefilter:styletypes">
{{wine.name}} is a {{wine.type}} with {{wine.style}} style from {{wine.country}}
</li>
(filters disabled with the checkboxes, countryfilter and winetypefilter ) Would result:
<li ng-repeat="wine in wines | stylefilter:styletypes">
{{wine.name}} is a {{wine.type}} with {{wine.style}} style from {{wine.country}}
</li>
of course you can enable disable your filter dynamically... there can be many ways to do it simplest solution that comes to my mind is just sending third parameters as a boolean to check if filter is enable or not...
here is filter sample...
app.filter('winetypefilter', function () {
return function(input, filter, isEnable) {
// if isEnable then filter out wines
if (isEnable) {
var result = [];
angular.forEach(input, function (wine) {
angular.forEach(filter, function (isfiltered, type) {
if (isfiltered && type === wine.type) {
result.push(wine);
}
});
});
return result;
}
// otherwise just do not any filter just send input without changes
else{
return input
}
};
});
and here is PLUNKER...
来源:https://stackoverflow.com/questions/24110189/how-to-dynamically-disable-a-filter-inside-ng-repeat