的.config,.RUN,AppCtrl - 放在哪里路线? [英] .config, .run, AppCtrl - where to put routes?

查看:154
本文介绍了的.config,.RUN,AppCtrl - 放在哪里路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找出AngularJS的的.config .RUN 函数之间的差异。我是用我的的.config 设立路线,但我确实有一些 $关于的观赏路线变化启动和成功事件。

I wanted to find out the difference between the .config and .run functions in AngularJS. I was using my .config for setting up routes, but I did have some $on's for watching route change start and success events.

然后我有些感动这个code到 .RUN ,因为我是具有的.config

I then moved some of this code to .run as I was having some dependency injection problems in .config.

我终于感动了一些给 CommonAppController 我已经在我的&LT设置;机身方式>

I finally moved some of this to a CommonAppController which I have set on my <body>.

我也有2个的,它似乎运行正常,但肯定这是不对的的.config

I also had 2 .config's and it seemed to be running ok, but surely this isn't right?

谁能给上使用哪种方法有点见识?

Can anyone give a little insight on which method to use?

推荐答案

配置块和运行块得到在应用引导不同点执行,并在他们的处置有不同的注射本地人。下面是你可以在 AngularJS文档查找摘要。

Configuration blocks and run blocks get executed at different points in the application bootstrap, and have different injection locals at their disposal. Here's a summary of what you can find in the AngularJS documentation.

配置模块提供商在注册过程中得到执行,只能被注入提供商和常数(请参阅模块(与 module.config()注册) .provider() module.constant())。这通常是您将配置应用程序范围内的东西,如 $ routeProvider 。的东西,需要在创建服务之前进行配置。

Configuration blocks (registered with module.config()) get executed during provider registration, and can only be injected providers and constants (see module.provider() and module.constant()). This is typically where you would configure application-wide stuff, such as the $routeProvider. Stuff that needs to be configured before the services are created.

运行块(与注册module.run())获取喷油器后执行所有的供应商。现在,所有的实例和常量可以被注射。这通常是在那里你会配置服务, $ rootScope ,活动等。

Run blocks (registered with module.run()) get executed after the injector has all the providers. Now, all instances and constants can be injected. This is typically where you would configure services, $rootScope, events and so on.

您可以有任多个,他们在他们注册到模块的顺序执行。有些人preFER各组控制器注册到这些控制器路由的前注册一个配置块,例如

You can have multiple of either, and they are executed in the order they were registered to the module. Some people prefer to register a configuration block before every group of controllers to register the routes to these controller, for example.

这篇关于的.config,.RUN,AppCtrl - 放在哪里路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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