角模块:加载顺序 [英] angular module: order of loading

查看:100
本文介绍了角模块:加载顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在官方文件angularjs发现那位出

I fount out in the official angularjs documents that

angular.module('富',[])使得富模块的定义,以及

angular.module('foo', []) makes the definition of foo module, and

angular.module('富')是调用(不做)富模块。

angular.module('foo') is calling (not making) foo module.

但是,当我写我无法启动我的应用程序下面的code,

But I could not start my app when I wrote the code below,

应用程序/控制器/ file1.js

VAR应用= angular.module('app.controller',[]);

应用程序/控制器/ file2.js

VAR应用= angular.module('app.controller');

app/controllers/file1.js var app = angular.module('app.controller', []); app/controllers/file2.js var app = angular.module('app.controller');

和,它工作时,我只改这两个声明:

and, it worked when I only changed those two declarations:

应用程序/控制器/ file1.js

VAR应用= angular.module('app.controller');

应用程序/控制器/ file2.js

VAR应用= angular.module('app.controller',[]);

app/controllers/file1.js var app = angular.module('app.controller'); app/controllers/file2.js var app = angular.module('app.controller', []);

所以...我想知道那个

so... I am wondering that


  • 如何加载模块的顺序决定

  • 我应该怎么办时,我想用同一模块上的两个或多个文件

感谢。

推荐答案

这是pretty简单:你必须创建模块的 以能够使用它之前,

It's pretty straightforward: you must create the module before to be able to use it.

这显然是一个坏主意控制器中的文件来创建它;使用一个单独的文件用于此目的,在其中也将能够使全球配置( myModule.config())的项目,例如中。你的情况:

It's clearly a bad idea to create it in a controller file; use a separate file for this purpose, in which you will also be able to make the global configuration (myModule.config()) of your project, for instance. In your case:

/** In "app/controller.js" **/
angular.module('app.controller', []); // Creation of the module

/** In "app/controllers/file1.js" **/
/** In "app/controllers/file2.js" **/
angular.module('app.controller'); // Use of the (already existing) module

文件应用程序/ controller.js 应首先调用。然后,将其它文件的顺序并不重要。

The file app/controller.js should be called first. Then, the order of the other files doesn't matter.

这篇关于角模块:加载顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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