ANGULARJS filter, the Chinese name "filter" is used to filter the value of variables, or format the output, get their desired results or format dongdong. Angularjs has a filterfilter function to filter the collection, which is very convenient.
The source code is roughly as follows:
function Filterfilter () {return
function (aray, expression comparator) {
if (!isarray (array)) return array;
var comparatortype = typeof (Comparator),
predicates = [],
evaluatedobjects = [];
Predicates.check = function (value) {for
(var j = 0; j < predicates.length; jii) {
if (!predicates[j) (value) { return
false;
})
}
return true;
}
if (comparatortype!= ' function ' {
if (Comparatortype = = ' Boolean ' && comparator) {
comparator = function (obj, text) {return
angular.equals (obj, text);
}
} else {
comparator = function (obj, text) {
...
}
}
})
}
}
The controller section is as follows:
Angular
. Module (' app ')
. Controller (' Mainctrl ', [' $scope ',
function ($scope) {
$scope. Users = $ Scope.users = [
{name: ', email: ', joined:2015-1-1}
];
$scope. Filter = {
fuzzy: ',
name: '
};
...
}]);
Search all any fields
<input type= "text" ng-model= "Filter.any" >
<tr ng-repeat= "User in Users | filter:filter.any" >
<td>{{user.name}}</td>
<td>{{user.email}}</td>
<td>{{user.joined | date} }</td>
</tr>
Search for a field
<input type= "text" ng-model= "Filter.name" >
<tr ng-repeat= "user in Users
| Filter:filter.any
| Filter: {name:filter.name} ' >
<td>{{user.name}}</td>
<td>{{user.email}}</td >
<td>{{user.joined | date}}</td>
</tr>
If you want the name field to match exactly:
<TR ng-repeat= "user in Users
| Filter:filter.any
| filter: {name:filter.name}:true" >
<td>{{ user.name}}</td>
<td>{{user.email}}</td>
<td>{{user.joined | date}}</td>
</tr>
Search time period
The Contrlller section is modified to:
Angular
. Module (' app ')
. Controller (' Mainctrl ', [' $scope ',
function ($scope) {
$scope. Users = $ Scope.users = [
{name: ', email: ', joined:2015-1-1}
];
$scope. Filter = {
fuzzy: ',
name: '
};
$scope. mindate = new Date (' January 1, n ');
$scope. maxdate = new Date ();
$scope. Min = function (actual, expected) {return
actual >= expected;
};
$scope. max = function (actual, expected) {return
actual <= expected;
}
]);
The page section is:
<input type= "text" ng-model= "FromDate" data-min-date= "{{mindate}}" ">
<input type=" text "ng-model=" Untildate "data-max-date=" {MaxDate}} ">
<tr ng-repeat=" user in Users
| Filter:filter.any
| filter: {Name:filter.name}
| Filter: {Joined:untildate}:max
| filter: {joined:beforedate}:min >
<td>{{user.name}}</td>
<td>{{user.email}}</td>
<td>{{user.joined | date}}</td>
</tr>
The above is a small set to share the ANGULARJS in how to use Filterfilter function filter related knowledge, hope to help you.