如何在Angularjs的单个模块中创建多个自定义过滤器 [英] How to create multiple custom filters within a single module in Angularjs
本文介绍了如何在Angularjs的单个模块中创建多个自定义过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在关注本教程,并相应地创建了自定义过滤器下方.然而,最后一个导致第一个消失.当您使用truncate
过滤器时,它是一个例外.如何在一个模块中创建多个过滤器?
I'm following this tutorial and created the underneath custom filters accordingly. The last one however causes the first one to disappear; when you use the truncate
filter it an exception. How do you create multiple filters within a module?
angular.module('filters', []).filter('truncate', function () {
return function (text, length, end) {
if (isNaN(length))
length = 10;
if (end === undefined)
end = "...";
if (text.length <= length || text.length - end.length <= length) {
return text;
}
else {
return String(text).substring(0, length-end.length) + end;
}
};
});
angular.module('filters', []).filter('escape', function () {
return function(text) {
encodeURIComponent(text);
};
});
推荐答案
angular.module('filters', []).filter("truncate", function() {})
.filter("escape", function() {});
这篇关于如何在Angularjs的单个模块中创建多个自定义过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文