请参考以下代码。
使用Angular过滤器,我可以搜索“friend.name”或“friend.phone”,也可以同时搜索两者,但是如何在组合了两者的字符串中进行搜索呢?例如,在下面的示例代码中,我想搜索“Mary-80”,它应该仅显示一个列表元素“Mary-800-BIG-MARY”。
如何实现这一点,请帮帮我。 是否可以使用默认的AngularJS过滤器来实现?
<!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链接:http://plnkr.co/edit/p7valhnDulHorw8xDYu8?p=preview