AngularJS app.run()文档? [英] AngularJS app.run() documentation?

查看:150
本文介绍了AngularJS app.run()文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何并app.run其中()使用吗?模块定义后的app.config(),app.controller后()后?

How and where is app.run() used? After module definition, after app.config(), after app.controller()?

我采用 BreezeJS角Q ,它要求某些code在应用程序中运行.RUN()函数。

I am adopting the BreezeJS Angular Q, which asks that certain code be run in the app.run() function.

推荐答案

下面是调用顺序:


  1. 的app.config()

  2. app.run()

  3. 指令的编译功能(如果它们在DOM中)

  4. app.controller()

  5. 指令的链接功能(同样,如果找到)

  1. app.config()
  2. app.run()
  3. directive's compile functions (if they are found in the dom)
  4. app.controller()
  5. directive's link functions (again, if found)

下面是一个简单的演示那里你可以观看每一个执行(和实验,如果你想)。

Here's a simple demo where you can watch each one executing (and experiment if you'd like).

从<一个href=\"https://github.com/angular/angular.js/blob/ce669edfa14dc7eb7c389d2f82c9c98399a9009b/docs/content/guide/module.ngdoc\">Angular's模块文档:

运行块 - 创建喷油器后得到执行,并
  使用的kickstart的
      应用。只有实例和常量可注入运行块。这是prevent
      在应用程序运行时进一步系统配置。

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.

运行块是角度的主要方法最接近。一个运行
  块是code这需要运行的kickstart应用程序。它
  所有的服务都被配置和执行后
  喷油器已创建。运行块通常包含code这是
  很难单元测试,基于这个原因,应予以隔离声明
  模块,使得它们可以在单元测试忽略

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 situation where run blocks are used is during authentications

这篇关于AngularJS app.run()文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆