I'm new to Angular and I was reading over the filter documentation and I saw this code.
<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">
I'm unclear on what the ng-model="search.$"
means. The two way binding with ng-model
is clear, but what about the "search.$"
? What is that doing and how does it work with the filter.
I tried searching for this and couldn't find anything. Thanks!
It is specific to the filter logic. $
is used as a property matcher to match against the values of all the properties on the object in the list. So here in your filter the bound expression is the object search
and specifying the matcher string as $
property (which is the ng-model for the search input) on search
will enable the filter to compare values on all the properties of friendObj
for a match.
See doc
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'}.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With