我是 Angular 的新手,我在阅读过滤器文档时看到了这段代码。
<label>Any: <input ng-model="search.$"></label> <br>
<label>Name only <input ng-model="search.name"></label><br>
<label>Phone only <input ng-model="search.phone"></label><br>
<tr ng-repeat="friendObj in friends | filter:search:strict">
我不清楚 ng-model="search.$"
的含义。与ng-model
的两种绑定(bind)方式很清楚,但是"search.$"
呢?那是做什么的,它是如何与过滤器一起工作的。
我尝试搜索此内容,但找不到任何内容。谢谢!
最佳答案
它特定于过滤器 逻辑。 $
用作属性匹配器,以匹配列表中对象的所有属性的值。因此,在您的过滤器中,绑定(bind)表达式是对象 search
并将匹配器字符串指定为 $
属性(这是搜索输入的 ng-model) search
将使过滤器能够比较 friendObj
的所有属性的值以进行匹配。
Note that a named property will match properties on the same level only, while the special $ property will match properties on the same level or deeper. E.g. an array item like {name: {first: 'John', last: 'Doe'}} will not be matched by {name: 'John'}, but will be matched by {$: 'John'}.
关于javascript - Ng-Model ="something.$"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33350861/