<html>
<head>
<script src="js/angular.min.js"></script>
<script type="text/javascript">
function windowScopedFilter (input) {
var output = [];
angular.forEach(input, function(v,k){
console.log(k+":"+ v);;
});
return output;
}
var myapp = angular.module('MyFilterApp', []);
myapp.filter('myfilter', function() {
return function(input, param1) {
console.log("------------------------------------------------- begin dump of custom parameters");
console.log("input=",input);
console.log("param1(string)=", param1);
var args = Array.prototype.slice.call(arguments);
console.log("arguments=", args.length);
if (3<=args.length) {
console.log("param2(string)=", args[2]);
}
if (4<=args.length) {
console.log("param3(bool)=", args[3]);
}
console.log("------------------------------------------------- end dump of custom parameters");
// filter
if (5<=args.length) {
return window[args[4]](input);
}
return input;
};
});
myapp.controller('MyFilterController', ['$scope', function($scope) {
$scope.friends = [{name:'John', phone:'555-1276'},
{name:'Annie', phone:'800-BIG-MARY'},
{name:'Mike', phone:'555-4321'},
{name:'Adam', phone:'555-5678'},
{name:'David', phone:'555-8765'},
{name:'Mikay', phone:'555-5678'}];
}]);
</script>
</head>
<body ng-app="MyFilterApp">
<div ng-controller="MyFilterController">
<table id="searchTextResults">
<tr><th>Name</th><th>Phone</th></tr>
<tr ng-repeat="friend in friends |myfilter:'John':'555-1276':true:'windowScopedFilter'">
<td>{{friend.name}}</td>
<td>{{friend.phone}}</td>
</tr>
</table>
</div>
<hr>
</body>
</html>
angular过滤器三
最新推荐文章于 2022-06-15 17:26:27 发布