我为我的 angularjs 项目创建了一个自定义过滤器,类似于以下小提琴http://jsfiddle.net/tUyyx/。
myapp.filter('truncate',function(text,length){
var end = "..."
text = text.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
if (isNaN(length))
length = 23;
if (text.length <= length || text.length - end.length <= length) {
return text;
}
else {
return String(text).substring(0, length-end.length) + end;
}
});
但是当我使用过滤器时出现以下错误
Error: Unknown provider: textProvider <- text <- truncateFilter
at Error (<anonymous>)
at http://localhost/javascripts/lib/angular.min.js:28:236
at Object.c [as get] (http://localhost/javascripts/lib/angular.min.js:26:13)
at http://localhost/javascripts/lib/angular.min.js:28:317
at c (http://localhost/javascripts/lib/angular.min.js:26:13)
at Object.d [as invoke] (http://localhost/javascripts/lib/angular.min.js:26:147)
at http://localhost/javascripts/lib/angular.min.js:28:335
at Object.c [as get] (http://localhost/javascripts/lib/angular.min.js:26:13)
at http://localhost/javascripts/lib/angular.min.js:99:481
at o (http://localhost/javascripts/lib/angular.min.js:66:471)
我已经像这样创建了我的模块。
var myapp = angular.module('myapp', ['ngResource']);
我究竟做错了什么?