I am trying to filter through multiple properties in Angular. I am able to filter through one property easily by using an angular filter:{ title: searchString } but to filter through a multiple properties... i created my own custom filter which tries to match the search string by any of the properties in the array.
What I need to do is:
If John Wayne is passed through.. it shows John Wayne but if only John or only Wayne is passed through... It still shows John Wayne. Similarly for n w since John ends with an n and subTitle starts with a w
PS: I can only have one ng-model
HTML:
<input type="text" ng-model="searchString">
<div ng-repeat="tel in arr1 | customFilter: searchString:['title','subTitle']"></div>
JS:
$scope.arr1 = [
{title: 'John', subTitle:'Wayne'}
{title: 'Barry'}
];
.filter('customFilter',[ function() {
return function(items, searchText, attrs) {
var filtered = [];
var filteredItems = items.map(function(item) {
angular.forEach(attrs, function(attr) {
if (item.hasOwnProperty(attr)) {
filtered.push(item);
}
});
});
return filtered;
};
}])
My issue is that I am getting an error saying:
Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: tel in arr1