【问题标题】:$injector:unpr Unknown provider: eProvider <- e <- debounce$injector:unpr 未知提供者:eProvider <- e <- debounce
【发布时间】:2016-01-11 23:00:28
【问题描述】:

我的应用中有以下控制器,它在我的机器上运行良好。当我推送到生产环境并缩小代码时,我收到以下错误:Error: [$injector:unpr] Unknown provider: eProvider &lt;- e &lt;- debounce。我正在努力调试这个错误。我发现的几乎所有关于该主题的帖子都表明问题出在我的依赖注入上,但我认为这不适用于我的情况。

var app = angular.module('myApp', ['ngAnimate','ui.bootstrap', 'ngFileUpload', 'rt.debounce']);

app.controller('SocialMediaCtrl', ['$scope', '$rootScope', '$http', '$timeout', '$location', '$q', '$compile', 'socialMediaAPI', 'inspirationsAPI', 'debounce', 'modal', function($scope, $rootScope, $http, $timeout, $location, $q, $compile, socialMediaAPI, inspirationsAPI, debounce, modal) {
    $scope.form = {};
    $scope.newPost = {
        token: $scope.token,
        post: $scope.post,
        posts: {
            twitter: null,
            facebook: null,
            linkedin: null
        },
        attachment_url: $scope.attachment_url,
        media_url: $scope.media_url,
        services: {
            twitter: $scope.twitter,
            facebook: $scope.facebook,
            linkedin: $scope.linkedin
        }
    };

    function getTweetLength(post) {
        $scope.tweetLength = post ? 140 - twttr.txt.getTweetLength(post) : 0;
        if($scope.tweetLength < 0) {
            $scope.tweetLengthValidation = true;
        } else {
            $scope.tweetLengthValidation = false;
        };
    };

    function getLinkedInPostLength(post) {
        var url = twttr.txt.extractUrls(post)[0];
        if(post && url) {
            $scope.linkedInPostLength = 256 - post.length + url.length;
        } else if (post && !url) {
            $scope.linkedInPostLength = 256 - post.length;
        } else {
            $scope.linkedInPostLength = 0;
        };

        if($scope.linkedInPostLength < 0) {
            $scope.linkedInPostLengthValidation = true;
        } else {
            $scope.linkedInPostLengthValidation = false;
        };
    };

    var getLengthValidations = debounce(10, function(evt){
        getTweetLength($(evt.target).val());
        getLinkedInPostLength($(evt.target).val());
        if($scope.newPost.services.twitter) {
            $scope.maxLength = 140;
        } else if ($scope.newPost.services.linkedin) {
            $scope.maxLength = 256;
        } else {
            $scope.maxLength = 1000;
        };
    });

    $('textarea').on('keyup keydown cut paste', function(e){
        getLengthValidations(e);
    })
}]);

注意:完整的控制器有 200 多行,因此为简洁起见,我省略了不相关的部分。

【问题讨论】:

  • 您是否尝试过将您的debounce(可能还有其他)的缩小版本替换为非缩小文件,以查看它是否实际上是最初引入错误的缩小版本?我看到一些库没有被缩小(或引入错误),因为一些特殊字符不能很好地与缩小器配合使用。

标签: angularjs angularjs-injector


【解决方案1】:

错误消息似乎表明debounce 提供程序实例需要e 提供程序实例。问题很可能不在您的控制器代码中,而是在定义debounce工厂/服务/等的代码中。我猜它没有定义DI数组。

出门在外,我会说你正在使用

bower_components/angular-debounce/src/debounce.js(无 DI)

而不是

bower_components/angular-debounce/dist/angular-debounce.js(有 DI)

【讨论】:

  • 一针见血。我认为错误指向控制器中的去抖动功能,但显然不是。
  • 你是个英雄。我复制了一个旧的工厂定义,它没有为 DI 使用较新的数组语法,然后得到了这个错误。您对 DI 数组的评论指出了问题所在,然后 [] 将其全部排序:)
猜你喜欢
  • 2017-04-28
  • 1970-01-01
  • 2014-10-25
  • 2016-05-09
  • 2017-04-16
  • 2014-10-01
  • 2023-03-08
  • 1970-01-01
  • 2017-04-25
相关资源
最近更新 更多