demo.html:
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>AngularJS</title>
<script src="angular.min.js"></script> <!-- 引入AngularJS架構 -->
</head>
<body ng-app="App">
<div ng-controller="DemoController">
<h3>{{name|demo:"哈哈"}}</h3> <!-- 使用自定義的過濾器 -->
</div>
<script>
var App = angular.module('App',[]);
App.filter('demo',function() {
return function(input,param) { // 第一個參數input是要處理的資料,第二個參數param是過濾器自己的參數
console.log(input);
return input + param; // 傳回處理後的資料
}
});
App.controller("DemoController",['$scope',function($scope) {
$scope.name = "小明";
}]);
</script>
</body>
</html>