2017-02-13 124 views
0

我有一個服務創建這樣:Angularjs未知服務提供商

(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模塊中,但還是不能注入它。

回答

2

服務在​​模塊中聲明,而控制器在'formOrderDialog'模塊中聲明。您需要注入authSite模塊才能從中訪問該服務。

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

加上一個很好檢測 – Sajeetharan

+0

這是問題,謝謝。 – tammy