1. 程式人生 > >《AngularJs》$filter 自定義過濾器

《AngularJs》$filter 自定義過濾器

使用內建過濾器直接查手冊就行了

下面為自定義過濾器:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="./js/angular.min.js"></script>
</head>
<body ng-app="myApp">
    <div ng-controller="MyController">
<p>姓名為
{{ lastName | myfilter }}</p> <p>姓名為 {{ name}}</p> </div> <script> var app = angular.module('myApp',[]); app.controller('MyController',['$scope','$filter',function($scope,$filter) { $scope.lastName = "abcd"; $scope.name = $filter('myfilter'
)('abcd'); }]); app.filter("myfilter",function(){ return function(input){ return input+"filter"; } });
</script> </body> </html>