簡體   English   中英

AngularJS Getting Unknown提供程序錯誤,將常量注入工廠

[英]AngularJS Getting Unknown provider error injecting a constant into a factory

嘗試將constant注入正在注入controllerfactory ,出現了unknown provider的角度錯誤的unknown provider錯誤。

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 ,這是阻止其執行的唯一方法。

我簡化了您的代碼,並在提琴上沒有錯誤地運行了它

    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);

您已將miEstimatingUtilitiesSettingsmiEstimatingUtilitiesSettingsEstimatingUtilitiesSettings

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM