Skip to content

Instantly share code, notes, and snippets.

@auxcoder
Created January 15, 2016 19:36
Show Gist options
  • Save auxcoder/92f6eab5cce3e98360be to your computer and use it in GitHub Desktop.
Save auxcoder/92f6eab5cce3e98360be to your computer and use it in GitHub Desktop.
Search by two atributes in an object (collections of customers)
(function() {
'use strict';
angular.module('engageAngularApp')
.filter('searchByNameAndPhone', function(){
return function(items, searchString){
if(!searchString){
return items;
}
var result = [];
searchString = searchString.toLowerCase();
angular.forEach(items, function(item){
if(item.customer.first_name.toLowerCase().indexOf(searchString) !== -1 || item.customer.home_phone.toLowerCase().indexOf(searchString) !== -1 || item.customer.last_name.toLowerCase().indexOf(searchString) !== -1){
result.push(item);
}
});
return result;
};
}
)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment