给出的示例中search
,search.$
和search.name
中的search.phone
是什么<table id="searchTextResults">
<tr><th>Name</th><th>Phone</th></tr>
<tr ng-repeat="friend in friends | filter:searchText">
<td>{{friend.name}}</td>
<td>{{friend.phone}}</td>
</tr>
</table>
<hr>
Any: <input ng-model="search.$"> <br>
Name only <input ng-model="search.name"><br>
Phone only <input ng-model="search.phone"><br>
Equality <input type="checkbox" ng-model="strict"><br>
<table id="searchObjResults">
<tr><th>Name</th><th>Phone</th></tr>
<tr ng-repeat="friendObj in friends | filter:search:strict">
<td>{{friendObj.name}}</td>
<td>{{friendObj.phone}}</td>
</tr>
</table>
:
{{1}}
答案 0 :(得分:1)
我自己已经弄明白了。表达式ng-model="search.$"
,ng-model="search.name"
和ng-model="search.phone"
在范围内使用属性$
,name
和phone
创建对象:
$scope.search = {
"$":"",
"name":"",
"phone":""
}
然后,该文档解释了这里的搜索表达式{{ filter_expression | filter : expression : comparator}}
可以有一个对象的形式:
Object: A pattern object can be used to filter specific properties on objects contained by array. For example {name:"M", phone:"1"} predicate will return an array of items which have property name containing "M" and property phone containing "1". A special property name $ can be used (as in {$:"text"}) to accept a match against any property of the object. That's equivalent to the simple substring match with a string as described above.
所以search
这里是由ng-model
创建的范围上的对象,它具有绑定到输入元素的属性。
答案 1 :(得分:0)
此处search
是您在下一行中作为expression
传递的对象。
<tr ng-repeat="friendObj in friends | filter:search:strict">
所以在ng-model
中你说的是search.$
,search.name
&amp; search.phone
。
我们假设您将a
放入输入search.$
,用filter:search:strict
替换filter:{$:'a'}:strict
。
当您将a
放入输入search.name
时,它会将filter:search:strict
替换为filter:{name:'a'}:strict
。
当您将a
放入输入search.phone
时,它会将filter:search:strict
替换为filter:{phone:'a'}:strict
。