我正在按照本教程编写相应的自定义过滤器.然而,最后一个导致第一个消失; 当你使用truncate过滤器时它是一个例外.如何在模块中创建多个过滤器?
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);
};
});
Run Code Online (Sandbox Code Playgroud)
小智 18
angular.module('filters', []).filter("truncate", function() {})
.filter("escape", function() {});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11035 次 |
| 最近记录: |