Studying AngularJS tutorial https://docs.angularjs.org/tutorial/step_05 . Also there is a live demo: http://angular.imtqy.com/angular-phonecat/step-5/app/

Search: <input ng-model="$ctrl.query" /> <li ng-repeat="phone in $ctrl.phones | filter:$ctrl.query"> <span>{{phone.name}}</span> <p>{{phone.snippet}}</p> </li> 

So: how does this very filter work: $ ctrl.query ? Obviously, the script cycles through the entire array of phones objects, and if there is a match with the entered text, the current value is returned to the output after filtering. But the filter is designed so that it looks at all the fields, even those that are not visually displayed. For example, if our phones array is:

 [ { "name": "Motorola XOOM with Wi-Fi", "snippet": " ... ", "sys": "hidden value" }, { "name": "MOTOROLA XOOM", "snippet": "... ", "sys": "hidden value" } ] 

and in <input ng-model="$ctrl.query" /> enter the hidden value , the filter will also work. Although I would like to filter only by the name field. Or implement a filter with a regular expression. Suppose you can replace any letter with an asterisk. In general, how to implement the filter function?

1 answer 1

A filter called filter "passes" an input array through itself and returns an array with elements that match the specified expression.
The filter has the form: {{ исходный_массив | filter : Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅_для_поиска : функция_сравнСния}} {{ исходный_массив | filter : Π²Ρ‹Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅_для_поиска : функция_сравнСния}}
In your case, use the standard function for comparison.

To search for a given field, you can do it by placing a query in the field with the name that you want to search for. I.e:
<li ng-repeat="phone in $ctrl.phones | filter:{name: $ctrl.query}">

To use regex you will need to write your own comparator:
To controller:

 this.comparator = function(source, query) { return (new RegExp(query)).test(source); } 

In the template:
<li ng-repeat="phone in $ctrl.phones | filter:{name: $ctrl.query}:$ctrl.comparator">