在angular中除了内置的过滤器外,angular还有自定义的过滤器filter
自定义过滤器有固定的语法结构
<div ng-controller="myCtrl">
<div ng-bind="name"></div>
<div ng-bind="name | myfilter"></div>
</div>
myfilter为过滤器自定义的名称,function为过滤器处理函数
app.filter("myfilter", function() {
return function(value) {
value = value.toUpperCase();
return value;
}
});
app.controller("myCtrl", function($scope) {
$scope.name = "jerry";
});
这是一个简单的大小写转换的自定义过滤器,
使用一个闭包函数,闭包函数中的value就是过滤器接收到的数据|就是准备过滤的数据,return function(value) {}是过滤器直接return的函数处理后的数据,value是用于接收要处理的数据,数据就是过滤器管道符前面变量中的数据