angularjs calling order
2015-08-03 15:47
501 查看
Here's the calling order:
app.config()
app.run()
directive's compile functions (if they are found in the dom)
app.controller()
directive's link functions (again if found)
Here's a simple demo where you can watch each execute (and experiment if you'd like).
From 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.
One place you see run blocks used is for authentication
app.config()
app.run()
directive's compile functions (if they are found in the dom)
app.controller()
directive's link functions (again if found)
Here's a simple demo where you can watch each execute (and experiment if you'd like).
From 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.
One place you see run blocks used is for authentication
相关文章推荐
- AngularJs学习笔记--Creating Services
- angular之directive定义对象说明
- Angularjs中的标签模式和html5模式
- 《AngularJS》5个实例详解Directive(指令)机制
- angularjs思维
- angular要点总结
- AngularJs学习笔记__2、输出Hello World
- sublime安装AngularJS插件
- sublime安装AngularJS插件
- angularJS 服务--$provide里factory、service方法
- angularJS 服务--$provide里factory、service方法
- angularJS--多个控制器之间的数据共享
- angularJS--多个控制器之间的数据共享
- angularjs源码阅读——invokeLater
- angularjs源码分析之:angularjs执行流程
- angularjs源码阅读——injector
- angularjs源码阅读——invokeLater
- AngularJS 最常用的八种功能
- AngularJS学习总结
- AngularJs学习笔记__1、初步了解AngularJS