Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 什么';引导法和运行法在角度上有什么区别?_Javascript_Angularjs - Fatal编程技术网

Javascript 什么';引导法和运行法在角度上有什么区别?

Javascript 什么';引导法和运行法在角度上有什么区别?,javascript,angularjs,Javascript,Angularjs,我目前正在使用bootstrapangular以这种方式运行我的应用程序: 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. 那么它们之间的区别是什么呢?这个run方法只添加了创建喷油器和初始化

我目前正在使用
bootstrap
angular以这种方式运行我的应用程序:

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.

那么它们之间的区别是什么呢?

这个
run
方法只添加了创建喷油器和初始化模块后需要调用的函数。这些函数通常包含初始化模块的方法。然而,
bootstrap
方法告诉
angular
创建注入器并开始执行添加了
config
run
方法的函数。所以执行的顺序大致如下:

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

有什么特别的原因吗?引导是通过在索引中添加ng app=“appName”来实现的。htmlI正在使用requirejs加载一组文件,当所有依赖项都解决后,我才能启动应用程序。我猜您不允许在引导函数中定义常量或值。我相信您也可以在引导中启用或禁用调试。@z.a.,引导方法不接受任何函数/句柄没有引导不会发生任何事情,
run
不是必需的