标签:class blog code java http ext
<!DOCTYPE html> <html ng-app="firstapp"> <head> <meta charset="utf-8" /> <title>Filter</title> <script type="text/javascript" src="http://code.angularjs.org/angular-1.0.1.min.js" ></script>
<script>
var app = angular.module(‘firstapp‘, []);
app.factory(‘data‘, function(){
return {
message : "I‘m a data from factory"
};
});
app.filter(‘firstfilter‘, function(message){
return function(message){
return message + ‘!!!!!!‘;
}
});
function firstController($scope, data){
$scope.data = data;
}
</script>
</head>
<body>
<div ng-controller="firstController">
<h1>{{data.message | firstfiler}}</h1>
</div>
</body>
</html>
app.filter(‘firstfilter‘, function(message){
return function(message){
return message + ‘!!!!!!‘;
}
});
通过app实例化一个filter,第一个参数为filter的名字,第二个参数是一个回调函数,参数message为
<h1>{{data.message | firstfiler}}</h1>
中的data.message,在回调函数中实现该filter的功能。
AngularJS-filer,布布扣,bubuko.com
标签:class blog code java http ext
原文地址:http://www.cnblogs.com/helbing/p/3790082.html