Angularjs未知服务提供商

时间:2017-02-13 17:07:33

标签: angularjs angularjs-injector

我以这种方式创建了一项服务:

(function () {
'use strict';
module.exports = siteAuthService;

angular
    .module('authSite', [])
    .factory('siteAuthService', ['$q', '$http', 'Requester', 'tsModulesService', siteAuthService]);


function siteAuthService($q, $http, Requester, tsModulesService) {

    var factoryDefinitionObject = {
        getUserByEmail: getUser,
        createUser: createSiteUser,
        recoverPassword: recoverPassword
    };


    return factoryDefinitionObject;

   ...


 }  
})();

我正在尝试注入此服务的控制器:

(function () {
'use strict';
angular
    .module('formOrderDialog')
    .controller('FormOrderDialogController', FormOrderDialogController)
    .filter('getById', getById)
;

FormOrderDialogController.$inject = ['tsModulesService', '$scope', '$q', '$http', '$uibModalInstance', 'params', '$filter', 'Requester', 'dateHelpers', '$translate', 'alertService', '$uibModal',
    'SaleLineFactory', 'tsPrintSelectService', 'tsPrintService', 'EntrySectorService', 'uiGridConstants', 'confirmationDialogService', 'siteAuthService'];

function FormOrderDialogController(tsModulesService, $scope, $q, $http, $uibModalInstance, params, $filter, Requester, dateHelpers, $translate, alertService, $uibModal,
                                   SaleLineFactory, tsPrintSelectService, tsPrintService, entrySectorService, uiGridConstants, confirmationDialogService, siteAuthService) {
       ...
       ...
   }
})();

和模块:

(function() {
'use strict';

const module = angular
    .module('formOrderDialog', [])
 ;

 })();

但我得到Error: [$injector:unpr] Unknown provider: siteAuthServiceProvider <- siteAuthService <- FormOrderDialogController

我也试过require("../../services/siteAuthService"); 它在formOrderDialog模块中,但仍然无法注入它。

1 个答案:

答案 0 :(得分:2)

服务在'authSite'模块中声明,而控制器在'formOrderDialog'模块中声明。您需要注入authSite模块才能从中访问服务。

const module = angular
    .module('formOrderDialog', ['authSite']);