Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular.module meaning of the second parameter "requires"

Tags:

angularjs

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.

like image 583
ecbrodie Avatar asked Apr 02 '14 03:04

ecbrodie


1 Answers

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"

like image 106
s4m0k Avatar answered Nov 15 '22 07:11

s4m0k