<!DOCTYPE html> <html ng-app="test"> <head> <title>hi</title> <meta charset="utf-8"> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script> <script type="text/javascript"> var app = angular.module('test', []); app.controller('testController', function($scope){ $scope.title = "是個好人"; }); app.filter('addTitle', function(){ return function(name, title){ return name + title; } }); </script> </head> <body ng-controller="testController"> <input type="text" ng-model="name" ng-init="name='王小明'"> <p ng-bind="name|addTitle:title"></p> </body> </html>
執行結果: