Angular The module value of the second parameter "requires"

Recall the method signature for angular.module . If the second parameter is specified requires, then we create a new module instead of retrieving the existing one. Of all the documents and examples I've seen, this parameter is always passed in an empty array when using it. My question is, what is requiresintended to be used for anything else than the Angular message to create a new module instead of getting an existing one? What happens if I pass it a non-empty array? Are these values ​​used for any other purpose? Links with solutions are highly appreciated. Thank.

+4
source share
2 answers

- (, ), .

( requires) : ( 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).

+5

, .

:

moduleA.js

var customModule = angular.module ('ModuleA');
// controller, services, factories , etc codes here

app.js( )

var app = angular.module ("app", ["ModuleA"]);

:

angular.module ("app");

, "". , JS , ""

+5

Source: https://habr.com/ru/post/1534575/


All Articles