Skip to content

Instantly share code, notes, and snippets.

@Rokt33r
Created May 27, 2015 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Rokt33r/569f518eddcce5e01a4a to your computer and use it in GitHub Desktop.
Save Rokt33r/569f518eddcce5e01a4a to your computer and use it in GitHub Desktop.
Angular propsFilter
app.filter('propsFilter', function() {
return function(items, props) {
var out = [];
if (angular.isArray(items)) {
items.forEach(function(item) {
var itemMatches = false;
var keys = Object.keys(props);
for (var i = 0; i < keys.length; i++) {
var prop = keys[i];
var text = props[prop].toLowerCase();
if (item[prop].toString().toLowerCase().indexOf(text) !== -1) {
itemMatches = true;
break;
}
}
if (itemMatches) {
out.push(item);
}
});
} else {
// Let the output be the input untouched
out = items;
}
return out;
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment