Created
May 27, 2015 17:31
-
-
Save Rokt33r/569f518eddcce5e01a4a to your computer and use it in GitHub Desktop.
Angular propsFilter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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