2 * @license AngularJS v1.0.0rc8
3 * (c) 2010-2012 Google, Inc. http://angularjs.org
11 * @name angular.Module
14 * Interface for configuring angular {@link angular.module modules}.
17 function setupModuleLoader(window) {
19 function ensure(obj, name, factory) {
20 return obj[name] || (obj[name] = factory());
23 return ensure(ensure(window, 'angular', Object), 'module', function() {
24 /** @type {Object.<string, angular.Module>} */
29 * @name angular.module
32 * The `angular.module` is a global place for creating and registering Angular modules. All
33 * modules (angular core or 3rd party) that should be available to an application must be
34 * registered using this mechanism.
39 * A module is a collocation of services, directives, filters, and configure information. Module
40 * is used to configure the {@link angular.module.AUTO.$injector $injector}.
43 * // Create a new module
44 * var myModule = angular.module('myModule', []);
46 * // register a new service
47 * myModule.value('appName', 'MyCoolApp');
49 * // configure existing services inside initialization blocks.
50 * myModule.config(function($locationProvider) {
52 * // Configure existing providers
53 * $locationProvider.hashPrefix('!');
57 * Then you can create an injector and load your modules like this:
60 * var injector = angular.injector(['ng', 'MyModule'])
63 * However it's more likely that you'll just use
64 * {@link angular.module.ng.$compileProvider.directive.ngApp ngApp} or
65 * {@link angular.bootstrap} to simplify this process for you.
67 * @param {!string} name The name of the module to create or retrieve.
68 * @param {Array.<string>=} requires If specified then new module is being created. If unspecified then the
69 * the module is being retrieved for further configuration.
70 * @param {Function} configFn Option configuration function for the module. Same as
71 * {@link angular.Module#config Module#config()}.
72 * @returns {module} new module with the {@link angular.Module} api.
74 return function module(name, requires, configFn) {
75 if (requires && modules.hasOwnProperty(name)) {
78 return ensure(modules, name, function() {
80 throw Error('No module: ' + name);
83 /** @type {!Array.<Array.<*>>} */
86 /** @type {!Array.<Function>} */
89 var config = invokeLater('$injector', 'invoke');
91 /** @type {angular.Module} */
92 var moduleInstance = {
94 _invokeQueue: invokeQueue,
95 _runBlocks: runBlocks,
99 * @name angular.Module#requires
100 * @propertyOf angular.Module
101 * @returns {Array.<string>} List of module names which must be loaded before this module.
103 * Holds the list of modules which the injector will load before the current module is loaded.
109 * @name angular.Module#name
110 * @propertyOf angular.Module
111 * @returns {string} Name of the module.
119 * @name angular.Module#provider
120 * @methodOf angular.Module
121 * @param {string} name service name
122 * @param {Function} providerType Construction function for creating new instance of the service.
124 * See {@link angular.module.AUTO.$provide#provider $provide.provider()}.
126 provider: invokeLater('$provide', 'provider'),
130 * @name angular.Module#factory
131 * @methodOf angular.Module
132 * @param {string} name service name
133 * @param {Function} providerFunction Function for creating new instance of the service.
135 * See {@link angular.module.AUTO.$provide#factory $provide.factory()}.
137 factory: invokeLater('$provide', 'factory'),
141 * @name angular.Module#service
142 * @methodOf angular.Module
143 * @param {string} name service name
144 * @param {Function} constructor A constructor function that will be instantiated.
146 * See {@link angular.module.AUTO.$provide#service $provide.service()}.
148 service: invokeLater('$provide', 'service'),
152 * @name angular.Module#value
153 * @methodOf angular.Module
154 * @param {string} name service name
155 * @param {*} object Service instance object.
157 * See {@link angular.module.AUTO.$provide#value $provide.value()}.
159 value: invokeLater('$provide', 'value'),
163 * @name angular.Module#constant
164 * @methodOf angular.Module
165 * @param {string} name constant name
166 * @param {*} object Constant value.
168 * Because the constant are fixed, they get applied before other provide methods.
169 * See {@link angular.module.AUTO.$provide#constant $provide.constant()}.
171 constant: invokeLater('$provide', 'constant', 'unshift'),
175 * @name angular.Module#filter
176 * @methodOf angular.Module
177 * @param {string} name Filter name.
178 * @param {Function} filterFactory Factory function for creating new instance of filter.
180 * See {@link angular.module.ng.$filterProvider#register $filterProvider.register()}.
182 filter: invokeLater('$filterProvider', 'register'),
186 * @name angular.Module#controller
187 * @methodOf angular.Module
188 * @param {string} name Controller name.
189 * @param {Function} constructor Controller constructor function.
191 * See {@link angular.module.ng.$controllerProvider#register $controllerProvider.register()}.
193 controller: invokeLater('$controllerProvider', 'register'),
197 * @name angular.Module#directive
198 * @methodOf angular.Module
199 * @param {string} name directive name
200 * @param {Function} directiveFactory Factory function for creating new instance of
203 * See {@link angular.module.ng.$compileProvider.directive $compileProvider.directive()}.
205 directive: invokeLater('$compileProvider', 'directive'),
209 * @name angular.Module#config
210 * @methodOf angular.Module
211 * @param {Function} configFn Execute this function on module load. Useful for service
214 * Use this method to register work which needs to be performed on module loading.
220 * @name angular.Module#run
221 * @methodOf angular.Module
222 * @param {Function} initializationFn Execute this function after injector creation.
223 * Useful for application initialization.
225 * Use this method to register work which needs to be performed when the injector with
226 * with the current module is finished loading.
228 run: function(block) {
229 runBlocks.push(block);
238 return moduleInstance;
241 * @param {string} provider
242 * @param {string} method
243 * @param {String=} insertMethod
244 * @returns {angular.Module}
246 function invokeLater(provider, method, insertMethod) {
248 invokeQueue[insertMethod || 'push']([provider, method, arguments]);
249 return moduleInstance;
260 * Closure compiler type information
263 * requires: !Array.<string>,
264 * invokeQueue: !Array.<Array.<*>>,
266 * service: function(string, Function):angular.Module,
267 * factory: function(string, Function):angular.Module,
268 * value: function(string, *):angular.Module,
270 * filter: function(string, Function):angular.Module,
272 * init: function(Function):angular.Module