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 existi
The second parameter is used to define 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.
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;
As you see, this property can be used to set up a hierarchy of dependencies as well (when ModuleFoo
depends on ModuleBar
depending on ModuleBaz
).
requires meaning an array of modules which your module depends.
example:
moduleA.js
var customModule = angular.module ('ModuleA');
// controller, services, factories , etc codes here
app.js (main app)
var app = angular.module ("app", ["ModuleA"]);
if I just use:
angular.module ("app");
It means that i'm just retrieving the module named "app". Which is useable when controllers or directives or factories is defined in a different JS files and you want to configure it to the module "app"