2016-12-15 12 views
1

我創建了一個app.js,這是我的應用程序。此外,我用角度組件創建了一些可用於顯示和編輯某些數據的邏輯。用一些詞語,我創建了2個不同的組件(網格,表單)和一些其他子組件,我使用黑盒等組件。這意味着在我在控制器狀態下的異步路由中,唯一我創建的是一個配置對象,並將其傳遞給組件,如參數。現在,我將這些組件一次性地包含到我的應用程序中。我想創建更多可重用的東西,就像另一個Angular應用程序模塊,第二個包含所有組件(黑盒),我的第一個應用程序是唯一需要包含的第二個模塊。這可能嗎?AngularJS創建另一個模塊,並將其作爲依賴添加到第一個

回答

1

你的意思是這樣的?

angular.module('app', [ 
    'app.components' 
]) 

angular.module('app.components', [ 
    'app.components.a', 
    'app.components.b' 
]) 

angular.module('app.components.a', [ 
    'something.here' 
]) 

angular.module('app.components.a').directive('myComponentA', function(){ 
return { 
    config_here: true 
} 
}) 

angular.module('app.components.b', [ 
    'something.here' 
]) 

angular.module('app.components.b').directive('myComponentB', function(){ 
return { 
    config_here: true 
} 
}) 

我不知道我是否正確理解你。你也不必用'app.components'打包component.A和component.B。無論您需要什麼,都可以將它們作爲依賴關係直接添加到其他模塊或「應用程序」模塊本身。

相關問題