Refer below code.
Using angular filter i can search friend.name or friend.phone or both but how to make search in string that combines both, like in below example code i want to make a search for "mary - 80" and it should display only one list element "Mary - 800-BIG-MARY".
How to do this, pls help me out. Is it possible with using default angularjs filter??
<!doctype html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
</head>
<body ng-app="">
<div ng-init="friends = [{name:'John', phone:'555-1276'},
{name:'Mary', phone:'800-BIG-MARY'},
{name:'Mike', phone:'555-4321'},
{name:'Adam', phone:'555-5678'},
{name:'Julie', phone:'555-8765'},
{name:'Juliette', phone:'555-5678'}]"></div>
<label>Search: <input ng-model="searchText"></label>
<li ng-repeat="friend in friends | filter: searchText">
<span>{{friend.name}} - {{friend.phone}}</span>
</li>
</body>
</html>
plunker link for same code: http://plnkr.co/edit/p7valhnDulHorw8xDYu8?p=preview
That's how angularJs filter works by default. If you want to filter by a specific combination of properties, then you have to implement your own filter function. Like here https://scotch.io/tutorials/building-custom-angularjs-filters
super simple example
$scope.customFilter = (item)=> {
//TODO: Add your own properties here
return item.someProperty == $scope.filterValue;
};
html
<htmlElement ng-repeat="item in itemList | filter:customFilter"></htmlElement>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加