2016-10-05 60 views
0

我在嘗試將constant注入正在注入controllerfactory時出現角度unknown provider錯誤。AngularJS獲取未知供應商錯誤將一個常數注入工廠

angular.js:13920 Error: [$injector:unpr] Unknown provider: estimatingUtilitiesSettingsProvider <- estimatingUtilitiesSettings <- templateResolutionDataService 

app.js:

angular 
    .module('main', [ 
     'ngResource' 
     , 'angulartics' 
     , 'angulartics.appinsights' 
     , 'envModule' 
     , 'gettext' 
     , 'webModule' 
     , 'serviceModule' 
    ]) 

    .controller('testPageController', [ 
     '$scope' 
    , '$http' 
    , '$resource' 
    , 'envModule' 
    , 'gettext' 
    , 'templateResolutionDataService' 
    , 'profileTemplateResolutionDataService' 
    , 'templateResolutionDataWithMultipleTemplatesService' 
    , 'partResolutionDataService' 
    , 'featureToggleService' 
    , 'recommendedResolutionDataService' 
    , 'profiledResolutionDataService' 
    , function ($scope, $http, $resource, envModule, gettext 
     , templateResolutionDataService 
     , profileTemplateResolutionDataService 
     , templateResolutionDataWithMultipleTemplatesService 
     , partResolutionDataService 
     , featureToggleService, recommendedResolutionDataService 
     , profiledResolutionDataService) { 
    //contents 
    }]); 

templateResolutionDataService.js:

(function (angular) { 
    'use strict'; 

    angular 
     .module('serviceModule', [ 
       'webModule' 
     ]) 
     .factory('templateResolutionDataService', [ 
       'gettext' 
      , 'estimateUtilitiesExtensionService' 
      , 'partResDataServiceSettings' 
      , 'estimatingUtilitiesSettings' 


      , function (gettext, estimatingUtilitiesService 
       , partResDataServiceSettings, estimatingUtilitiesSettings) { 
      } 
    ]); 
})(window.angular); 

webModule.js:

(function (angular) { 
    'use strict'; 

    angular 
     .module('webModule', [ 
      'ng' 
      , 'ngResource' 
      ,'miEnvironment' 
      ,'gettext' 
      ,'analyticsFilters' 
      ,'touchEvents' 
      ,'flyoutModule' 
     ]) 
     .constant('estimatingUtilitiesSettings', { 
      SourceKeys: { 
       'Template': 1 
       ,'Part': 2 
      } 
     }); 
})(window.angular); 

我一直在調整繼承順序,但它不似乎沒有解決這個問題。有誰知道我做錯了什麼,或者我可能如何識別和解決它?

編輯:註釋掉不變的聲明(手動用適當的值替換它的引用)確實允許應用程序繼續過去的這一點,所以在關於templateResolutionData.js這是防止其執行的唯一的事情。

+2

運行它不應該是'miEstimatingUtilitiesSettings',而不是'estimatingUtilitiesSettings'? –

+0

我搞砸了複製它,mi不應該在那裏,不在代碼中 –

+0

是否所有的模塊定義都正在執行?由於沒有腳本標記或語法錯誤,從未執行代碼時發佈的錯誤很常見。 – tcooc

回答

2

我已經簡化了你的代碼,並沒有錯誤上fiddle

angular.module('main', ['webModule', 'serviceModule']) 
    .controller('testPageController', [ 
    '$scope', '$http', 'templateResolutionDataService', 
    function($scope, $http, templateResolutionDataService) { 
     //contents 
     $scope.setting = templateResolutionDataService; 
    } 
    ]); 

(function(angular) { 
    'use strict'; 

    angular.module('serviceModule', [ 
     'webModule' 
    ]) 
    .factory('templateResolutionDataService', ['estimatingUtilitiesSettings', 
     function(estimatingUtilitiesSettings) { 
     var getSetting = function() { 
      return estimatingUtilitiesSettings.SourceKeys; 
     } 

     return getSetting(); 
     } 
    ]); 
})(window.angular); 

(function(angular) { 
    'use strict'; 
    angular.module('webModule', []) 
    .constant('estimatingUtilitiesSettings', { 
     SourceKeys: { 
     'Template': 1, 
     'Part': 2 
     } 
    }); 
})(window.angular); 
+0

我很高興知道它至少應該工作。我不得不使用它來替換所有文件中的常量,以使其在我的項目中正常工作。你有什麼想法,爲什麼我會不斷注入這麼多麻煩? –

+0

現在實際上它正在工作。我改變了一切,但今天它工作。 –

0

您已經名不副實miEstimatingUtilitiesSettingsEstimatingUtilitiesSettings

+0

是的,當我複製代碼時,它已經犯了一個錯誤,它已被更新。 –

+0

不是downvoter,但這不能從技術上回答這個問題。 –

+0

明天早上我會看看這個IST,如果它仍然沒有解決,謝謝你讓我知道^ – nikjohn

相關問題