自定义过滤器filter

来源:互联网 发布:软件开发北京 编辑:程序博客网 时间:2024/05/17 09:03
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="angularjs/angular.js"></script>
        <script>
            var app = angular.module("myApp",[]);
            app.controller("myCtrl",function($scope){
                $scope.haha = "wozhendeshi ";
            });
            //调用filter()方法自定义过滤器
            app.filter("myFilter",function(){
                return function(text){
                    return text.replace(/hello/,"你好");
                }
            });
        </script>
    </head>
    <body ng-app="myApp" ng-controller="myCtrl">
        <p>{{haha | myFilter}}</p>
    </body>
</html>

原创粉丝点击