AngularJS获取未知的提供程序错误将常量注入工厂

时间:2016-10-05 16:18:25

标签: javascript angularjs

我尝试将unknown provider注入正在注入constant的{​​{1}}时出现角度factory错误。

controller

app.js:

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

templateResolutionDataService.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
  }]);

webModule.js:

(function (angular) {
    'use strict';

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


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

我一直在调整继承顺序,但它似乎并没有解决这个问题。有谁知道我做错了什么,或者我怎么识别和解决它?

编辑:注释掉常量的声明(并用适当的值手动替换它的引用)确实允许应用程序继续超过这一点,因此关于{{1这是阻止其执行的唯一因素。

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:0)

您将miEstimatingUtilitiesSettings误称为EstimatingUtilitiesSettings