html angular自定义过滤器,指定所需要替换的文字

来源:互联网 发布:周继红 田亮 知乎 编辑:程序博客网 时间:2024/06/06 00:57
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript" src="angular.js" ></script>
            <script>
                var app = angular.module("myApp",[]);
                app.controller("myCtrl",function($scope){
                    $scope.haha = "hello,angular";
                });
                //调用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>
原创粉丝点击