AngularJS app.run()文档?

前端之家收集整理的这篇文章主要介绍了AngularJS app.run()文档?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
app.run()如何使用和在哪里使用?模块定义后,在app.config()或之后的app.controller()?

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

这是呼叫顺序:

> app.config()
> app.run()
>指令的编译函数(如果他们在dom中找到)
> app.controller()
>指令的链接功能(再次,如果发现)

这里有一个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 service 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.

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

原文链接:/angularjs/147862.html

猜你在找的Angularjs相关文章