I\'m trying to write an angularjs custom filter that checks whether an array of countries contains a search string entered by the user.
The string can consist of on
It is much simpler than that, use the String.indexOf() function:
angular.forEach(items, function(item) {
if( item.label.indexOf(searchText) >= 0 ) filtered.push(item);
});
You may want to turn both strings .toLowerCase() to do case-insensitive matching:
searchText = searchText.toLowerCase();
angular.forEach(items, function(item) {
if( item.label.toLowerCase().indexOf(searchText) >= 0 ) filtered.push(item);
});