2015-10-14 137 views
0

我在我的應用程序中有以下控制器,該控制器在我的機器上正常工作。當我推動生產並縮小代碼時,出現以下錯誤:Error: [$injector:unpr] Unknown provider: eProvider <- e <- 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行,所以爲了簡潔起見我省略了不相關的部分。

+0

您是否嘗試過更換你可以使用非縮小文件來縮小你的debounce(可能還有其他的文件),看它是否實際上是引入了錯誤的縮小版本?我看到一些圖書館沒有被縮小(或者引入錯誤),因爲一些特殊的人物與縮小機構不配合。 –

回答

1

錯誤消息似乎表明debounce提供程序實例需要提供商實例e。問題很可能不在您的控制器代碼中,而是在定義debounce工廠/服務等的代碼中。我猜測它沒有定義DI數組。

的肢體走出去,我說你正在使用

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

,而不是

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

+0

釘在頭上。我認爲這個錯誤是指向我的控制器中的去抖功能,但顯然不是。 – ACIDSTEALTH

相關問題