2014-11-23 158 views
1

我目前使用bootstrap角以這種方式運行我的應用程序:bootstrap方法和run方法在角度上有什麼區別?

ng.bootstrap(document, ['main']); 

角文檔指出

Run blocks are the closest thing in Angular to the main method. 
A run block is the code which needs to run to kickstart the application. 

那麼什麼是它們之間的區別?

+0

這樣做的特殊原因?引導是通過在您的index.html中添加ng-app =「appName」來實現的 – 2014-11-23 18:22:36

+0

我正在使用requirejs加載一堆文件,當所有依賴關係解析後我才能啓動應用程序 – 2014-11-23 18:25:27

+0

我猜你不允許在引導函數中定義常量或值。我相信你也可以在bootstrap中啓用或禁用調試。 – 2014-11-23 20:53:06

回答

1

run方法只是添加了一些函數,一旦創建注入器並初始化模塊,就需要調用這些函數。這些函數通常包含intitialize模塊的方法。而bootstrap方法則告知angular創建注入器並開始執行添加了configrun方法的函數。所以執行順序大致如下:

1. Create injector 
2. Execute functions added with config() method for each module 
3. Execute functions added with run() method for each module 
4. Start compilation phase 
5. Start linking phase 
相關問題