首页 > 技术文章 > 自定义过滤器

xqschool 2016-12-30 17:24 原文

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>

  

  

推荐阅读