According to the official documentation, there are several ways to achieve this: {{ filter_expression | filter : expression : comparator}}
1. As the method given by Guox, use expression:
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".
Used as an Object, used to filter specified attributes of array elements, such as expression = {name: "M", phone: "1"}, then the array whose name contains 'M' and phone contains '1' will be filtered out element.
So just use the following method
<li ng-repeat="phone in phones|filter:{name:query}">
2. You can use comparator:
Comparator which is used in determining if the expected value (from the filter expression) and actual value (from the object in the array) should be considered a match. function(actual, expected): The function will be given the object value and the predicate value to compare and should return true if both values should be considered equal.
The return value of Comparator can be used to determine whether there is a match. The input parameters are actual (elements in the array) and expected (input)
Then define a function
$scope.customerFilter = customerFilter;
function customerFilter(actual, expected){
return actual.name.contains(expexted) ? true : false;
}
前端使用
<li ng-repeat="phone in phones|filter:query:customerFilter">
<li ng-repeat="phone in phones|filter:{'name': query}">
According to the official documentation, there are several ways to achieve this:
{{ filter_expression | filter : expression : comparator}}
1. As the method given by Guox, use expression:
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".
Used as an Object, used to filter specified attributes of array elements, such as expression = {name: "M", phone: "1"}, then the array whose name contains 'M' and phone contains '1' will be filtered out element.
So just use the following method
2. You can use comparator:
Comparator which is used in determining if the expected value (from the filter expression) and actual value (from the object in the array) should be considered a match.
function(actual, expected): The function will be given the object value and the predicate value to compare and should return true if both values should be considered equal.
The return value of Comparator can be used to determine whether there is a match. The input parameters are actual (elements in the array) and expected (input)
Then define a function
Thank you both so much, thank you