Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angularjs过滤器错误:";错误:未知提供程序:textProvider";_Javascript_Angularjs - Fatal编程技术网

Javascript Angularjs过滤器错误:";错误:未知提供程序:textProvider";

Javascript 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

我为我的angularjs项目创建了一个自定义过滤器,类似于下面的fiddle


我做错了什么

如果您查看该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
        }
    }
});