AngularJs练习Demo8 自定义过滤器

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>自定义过滤器</title>
    <script type="text/javascript" src="~/Scripts/angular.js"></script>
    <script src="~/Scripts/js/filter.js"></script>
</head>
<body>
    <div ng-app="myApp">
        <div ng-controller="firstController">
            {{name|rHello}}
            {{name|rjs}}
        </div>
    </div>
    <script type="text/javascript">
        var app = angular.module("myApp", ["myApp.Fileter"]);
        app.controller("firstController", function ($scope) {
            $scope.name = "Hello Angularjs";

        });
        app.filter("rHello", function () {//自定义过滤器
            return function (input,n1,n2) {
                return input.replace(/Hello/,"你好");
            }
        });
    </script>
</body>
</html>

  

 

 

var appFileter = angular.module("myApp.Fileter", []);
appFileter.filter("rjs", function () {//自定义过滤器
    return function (input, n1, n2) {
        return input.replace(/js/, "javascript");
    }
});

 

posted @ 2016-06-21 23:03  编程猴子  阅读(215)  评论(0编辑  收藏  举报