自定义过滤器
myApp.filter(
'to_trusted', ['$sce', function ($sce) {
return function (text) {
return $sce.trustAsHtml(text);
}
}]
)
myAppModule.filter("reverse",function(){ return function(input,uppercase){ var out = ""; for(var i=0 ; i<input.length; i++){ out = input.charAt(i)+out; } if(uppercase){ out = out.toUpperCase(); } return out; } });
<div ng-controller="myAppCtrl"> name:{{ name }}<br> reverse name:{{ name | reverse }}<br> reverse&uppercase name:{{ name | reverse:true }} </div>