首页 > 代码库 > -_-#【Angular】自定义过滤器

-_-#【Angular】自定义过滤器

AngularJS学习笔记

 

<!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:‘&gt;&gt;‘:‘(no)‘ }}</p>       <p>示例数据: {{ b|map:map_value:‘&gt;&gt;‘:‘(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>

 

-_-#【Angular】自定义过滤器