第二个参数&QUOT的angular.module意义;要求" [英] angular.module meaning of the second parameter "requires"

查看:149
本文介绍了第二个参数&QUOT的angular.module意义;要求"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

回忆一下 angular.module 方法签名。如果第二个参数,要求提供,那么我们正在创造一个新的模块,而不是获取现有的。从我所看到的所有文档和例子,当使用该参数总是传递一个空数组。我的问题是,是要求意在用于任何除了告诉角度来创建一个新的模块,而不是让现有的其他人?如果我不是传给了一个非空数组,会发生什么?用于任何其他目的的价值?与解决方案的链接是多少AP preciated。谢谢你。

Recall the method signature for angular.module. If the second parameter, requires is provided, then we are creating a new module instead of retrieving an existing one. From all the documentation and examples I've seen, this parameter is always passed an empty array when used. My question is, is requires meant to be used for anything else besides telling Angular to create a new module instead of getting an existing one? What would happen if I instead passed it a non-empty array? Are those values used for any other purpose? Links with solutions are much appreciated. Thanks.

推荐答案

第二个参数是用来定义模块的依赖关系 - 即模块列表(模块名称,以precise),应该是已经加载由喷射器之前,在当前模块加载

The second parameter is used to defined the module's dependencies - i.e., a list of modules (module names, to be precise) that should be already loaded by the injector before the current module is loaded.

下面是这个参数是如何(存储在模块的要求属性)用于:(的 injector.js / loadModules() ):

And here's how this param (stored in the module's requires property) is used: (injector.js/loadModules()):

var runBlocks = [], moduleFn, invokeQueue, i, ii;
forEach(modulesToLoad, function(module) {
  if (loadedModules.get(module)) return; // skipping already loaded modules
  loadedModules.put(module, true);

  if (isString(module)) {
    moduleFn = angularModule(module); // prepared module object
    runBlocks = runBlocks.concat(loadModules(moduleFn.requires))
                         .concat(moduleFn._runBlocks);
    // ...
  }
  // ...
}
return runBlocks;

如你所见,这个属性可以用来建立依赖关系的层次结构,以及时( ModuleFoo 取决于 ModuleBar 根据 ModuleBaz )。

这篇关于第二个参数&QUOT的angular.module意义;要求"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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