gpt4 book ai didi

AngularJS app.run() 文档?

转载 作者:行者123 更新时间:2023-12-02 22:19:11 32 4
gpt4 key购买 nike

如何以及在何处使用app.run()?在模块定义之后,在 app.config() 之后还是在 app.controller() 之后?

我正在采用BreezeJS Angular Q ,询问某些代码是否可以在 app.run() 函数中运行。

最佳答案

这是调用顺序:

  1. app.config()
  2. app.run()
  3. 指令的编译函数(如果在 dom 中找到)
  4. app.controller()
  5. 指令的链接函数(如果找到的话)

这是一个simple demo您可以在其中观看每个操作的执行情况(如果您愿意,还可以进行实验)。

来自Angular's module docs :

Run blocks - get executed after the injector is created and are used to kickstart the application. Only instances and constants can be injected into run blocks. This is to prevent further system configuration during application run time.

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. It is executed after all of the services have been configured and the injector has been created. Run blocks typically contain code which is hard to unit-test, and for this reason should be declared in isolated modules, so that they can be ignored in the unit-tests.

使用运行 block 的一种情况是在authentications期间。 .

关于AngularJS app.run() 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20663076/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com