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"); } });