标签:
<!DOCTYPE html> <html ng-app="Demo"> <head> <meta charset="utf-8"> <title></title> </head> <body ng-init="a=‘222‘"> <script src="jquery-1.8.3.min.js"></script> <script src="angular.min.js"></script> <p>示例数据: {{ a|map }}</p> <script> var app = angular.module(‘Demo‘, [], angular.noop) app.filter(‘map‘, function() { var filter = function(input) { return input + ‘...‘ } return filter }); </script> </body> </html>
过滤器也可以带参数,多个参数之间使用:分割
<!DOCTYPE html> <html ng-app="Demo"> <head> <meta charset="utf-8"> <title></title> </head> <body> <script src="jquery-1.8.3.min.js"></script> <script src="angular.min.js"></script> <div ng-controller="TestCtrl"> <p>示例数据: {{ a|map:map_value:‘>>‘:‘(no)‘ }}</p> <p>示例数据: {{ b|map:map_value:‘>>‘:‘(no)‘ }}</p> </div> <script> var app = angular.module(‘Demo‘, [], angular.noop) app.controller(‘TestCtrl‘, function($scope) { $scope.map_value = { a: ‘一‘, b: ‘二‘, c: ‘三‘ } $scope.a = ‘a‘ }) app.filter(‘map‘, function() { var filter = function(input, map_value, append, default_value) { console.log(input, map_value, append, default_value) var r = map_value[input] if (r === undefined) { return default_value + append } else { return r + append } } return filter }) </script> </body> </html>
标签:
原文地址:http://www.cnblogs.com/jzm17173/p/4217831.html