首页 > 代码库 > anjularjs-filter,directer

anjularjs-filter,directer

1、过滤器

<!doctype html>
<!-- ng-app使用范围HTML -->
<html lang="en" ng-app="test">  
<head>
    <meta <meta charset=" " set="UTF-8">
    <title>Document</title>
    <style type="text/css" media="screen">
        #div1 input {background: #CCC;}
        #div1 input.active {background: yellow;}
        #div1 div {width: 200px;height: 200px;border: 1px solid #000;}
    </style>
    <script src="http://www.mamicode.com/angular.min.js"></script>
    <script type="text/javascript">
        var app=angular.module(‘test‘, []) 
        app.controller(‘cont1‘,  function($scope){
            $scope.arr=[12.4,12,3,44]
            $scope.timer=12341341234
        })

        app.filter(‘my_filter‘,function () {
            //只执行一次,进行初始化
            //alter()
            return  function (input) {
                //执行多次
                return input+19
            }
        })

    </script>
    <style type="text/css" media="screen">
    </style>
</head>
<body ng-controller="cont1">    
    <ul>
        <li ng-repeat="v in arr">{{v|my_filter}}:{{timer|date:‘yyyy年MM月dd日‘}}</li>
    </ul>
</body>
</html>


anjularjs-filter,directer