2015-08-13 21 views
1

我已在在app.js角 - 在多個文件中定義模塊

config = angular.module('config', []) 
.constant('Constants', { 
     Car: 'BMW', 
     Phone: 'G4' 
}); 

services = angular.module('services', ['config']); 
controllers = angular.module('controllers', ['config', 'services']); 
app = angular.module('myApp', ['config', 'controllers']); 

我想將「配置」模塊定義移動到一個單獨的文件,因爲我希望它做大以下。

是否有可能下面的部分轉移到一個單獨的文件:

config = angular.module('config', []) 
.constant('Constants', { 
     Car: 'BMW', 
     Phone: 'G4' 
}); 
+0

你不能改變的常數值之前加載.... –

+0

可以有無數files..not清楚確切的問題是什麼,或者什麼你在問。但是,應該將模塊分組爲功能而不是組件 – charlietfl

+0

爲了清晰起見,我編輯了該問題。 –

回答

1

這樣做沒有問題。

你只需要確保的配置模塊將應用程序模塊

0

您已經選擇了非常糟糕的結構爲您的角度應用。請檢查這個網址https://scotch.io/tutorials/angularjs-best-practices-directory-structure

而關於你的問題。而不是使用緩存變量只是做下一件事:

file0: angular.module('config',[]); 
file1: angular.module('config').constant('Constants', {Car: 'BMW', Phone: 'G4'}); 
file2: angular.module('config').constant('Constants2', {Car: 'BMW', Phone: 'G4'}); 
+0

我還沒有提到任何關於我的目錄結構。它完全符合最佳實踐。 –

+0

我們可以從一切聲明的方式看到你的結構,vlad是正確的imo。他提供的鏈接也非常好。 –