引导方法和运行方法之间的角度有什么区别

what's the difference in angular between bootstrap method and run method?

本文关键字:方法 什么 区别 之间 运行      更新时间:2023-09-26

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

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

Angular 文档指出

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创建注入器并开始执行使用 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