Javascript Angularjs过滤器错误:";错误:未知提供程序:textProvider";
我为我的angularjs项目创建了一个自定义过滤器,类似于下面的fiddleJavascript Angularjs过滤器错误:";错误:未知提供程序:textProvider";,javascript,angularjs,Javascript,Angularjs,我为我的angularjs项目创建了一个自定义过滤器,类似于下面的fiddle 我做错了什么 如果您查看该jsFiddle中的代码,该filter函数将返回一个以textetc作为参数的函数。应该是这样的: myapp.filter('truncate',function(){ return function(text, length) { var end = "..." text = text.replace(/\w\S*/g, function(txt
我做错了什么 如果您查看该jsFiddle中的代码,该filter函数将返回一个以
text
etc作为参数的函数。应该是这样的:
myapp.filter('truncate',function(){
return 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;
}
}
});
myapp.filter('truncate', function(myService) {
if (myService.someCondition()) {
return function(text, length) {
// return the text as usual
}
} else {
return function(text, length) {
// return the text and do some other things as well
}
}
});
var myapp = angular.module('myapp', ['ngResource']);
myapp.filter('truncate',function(){
return 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;
}
}
});
myapp.filter('truncate', function(myService) {
if (myService.someCondition()) {
return function(text, length) {
// return the text as usual
}
} else {
return function(text, length) {
// return the text and do some other things as well
}
}
});