2017-11-14 7 views
0

mainsecondaryの2つのモジュールを持つ角度1のアプリがあります。 secondarymainに注入され、そしてメインは持ってserviceAngular 1の注入モジュールからのアクセスサービス

angular.module('main', ['secondary']) 
.run(function(){ 
    console.log('main module run'); 
}) 
.service('mainService', function(){ 
    this.servMeth = function(){ 
    console.log('main service'); 
    }; 
}); 

angular.module('secondary', []) 
.run(function(){ 
    console.log('secondary module run'); 
}); 

secondaryモジュールにmainからmainServiceにアクセスする方法はありますか?

答えて

1

あなたはちょうどこのようなコンポーネントまたは他のサービスでそれを注入する必要があります。

angular.module('secondary', []) 
.run(function(){ 
    console.log('secondary module run'); 
}) 
.component('secondary-component', { 
    controller: ['mainService', function(mainService) { 
    this.$onInit = function() { 
     mainService.servMeth(); 
    } 
    }] 
}); 
関連する問題