2 * @license AngularJS v1.0.0rc2
3 * (c) 2010-2012 AngularJS 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) {
51 * // Configure existing providers
52 * $locationProvider.hashPrefix('!');
56 * Then you can create an injector and load your modules like this:
59 * var injector = angular.injector(['ng', 'MyModule'])
62 * However it's more likely that you'll just use
63 * {@link angular.module.ng.$compileProvider.directive.ng-app ng-app} or
64 * {@link angular.bootstrap} to simplify this process for you.
66 * @param {!string} name The name of the module to create or retrieve.
67 * @param {Array.<string>=} requires If specified then new module is being created. If unspecified then the
68 * the module is being retrieved for further configuration.
69 * @param {Function} configFn Option configuration function for the module. Same as
70 * {@link angular.Module#config Module#config()}.
71 * @returns {module} new module with the {@link angular.Module} api.
73 return function module(name, requires, configFn) {
74 if (requires && modules.hasOwnProperty(name)) {
77 return ensure(modules, name, function() {
79 throw Error('No module: ' + name);
82 /** @type {!Array.<Array.<*>>} */
85 /** @type {!Array.<Function>} */
88 var config = invokeLater('$injector', 'invoke');
90 /** @type {angular.Module} */
91 var moduleInstance = {
93 _invokeQueue: invokeQueue,
94 _runBlocks: runBlocks,
98 * @name angular.Module#requires
99 * @propertyOf angular.Module
100 * @returns {Array.<string>} List of module names which must be loaded before this module.
102 * Holds the list of modules which the injector will load before the current module is loaded.
108 * @name angular.Module#name
109 * @propertyOf angular.Module
110 * @returns {string} Name of the module.
118 * @name angular.Module#provider
119 * @methodOf angular.Module
120 * @param {string} name service name
121 * @param {Function} providerType Construction function for creating new instance of the service.
123 * See {@link angular.module.AUTO.$provide#provider $provide.provider()}.
125 provider: invokeLater('$provide', 'provider'),
129 * @name angular.Module#factory
130 * @methodOf angular.Module
131 * @param {string} name service name
132 * @param {Function} providerFunction Function for creating new instance of the service.
134 * See {@link angular.module.AUTO.$provide#factory $provide.factory()}.
136 factory: invokeLater('$provide', 'factory'),
140 * @name angular.Module#service
141 * @methodOf angular.Module
142 * @param {string} name service name
143 * @param {Function} constructor A constructor function that will be instantiated.
145 * See {@link angular.module.AUTO.$provide#service $provide.service()}.
147 service: invokeLater('$provide', 'service'),
151 * @name angular.Module#value
152 * @methodOf angular.Module
153 * @param {string} name service name
154 * @param {*} object Service instance object.
156 * See {@link angular.module.AUTO.$provide#value $provide.value()}.
158 value: invokeLater('$provide', 'value'),
162 * @name angular.Module#constant
163 * @methodOf angular.Module
164 * @param {string} name constant name
165 * @param {*} object Constant value.
167 * Because the constant are fixed, they get applied before other provide methods.
168 * See {@link angular.module.AUTO.$provide#constant $provide.constant()}.
170 constant: invokeLater('$provide', 'constant', 'unshift'),
174 * @name angular.Module#filter
175 * @methodOf angular.Module
176 * @param {string} name filter name
177 * @param {Function} filterFactory Factory function for creating new instance of filter.
179 * See {@link angular.module.ng.$filterProvider#register $filterProvider.register()}.
181 filter: invokeLater('$filterProvider', 'register'),
185 * @name angular.Module#directive
186 * @methodOf angular.Module
187 * @param {string} name directive name
188 * @param {Function} directiveFactory Factory function for creating new instance of
191 * See {@link angular.module.ng.$compileProvider.directive $compileProvider.directive()}.
193 directive: invokeLater('$compileProvider', 'directive'),
197 * @name angular.Module#config
198 * @methodOf angular.Module
199 * @param {Function} configFn Execute this function on module load. Useful for service
202 * Use this method to register work which needs to be performed on module loading.
208 * @name angular.Module#run
209 * @methodOf angular.Module
210 * @param {Function} initializationFn Execute this function after injector creation.
211 * Useful for application initialization.
213 * Use this method to register work which needs to be performed when the injector with
214 * with the current module is finished loading.
216 run: function(block) {
217 runBlocks.push(block);
226 return moduleInstance;
229 * @param {string} provider
230 * @param {string} method
231 * @param {String=} insertMethod
232 * @returns {angular.Module}
234 function invokeLater(provider, method, insertMethod) {
236 invokeQueue[insertMethod || 'push']([provider, method, arguments]);
237 return moduleInstance;
248 * Closure compiler type information
251 * requires: !Array.<string>,
252 * invokeQueue: !Array.<Array.<*>>,
254 * service: function(string, Function):angular.Module,
255 * factory: function(string, Function):angular.Module,
256 * value: function(string, *):angular.Module,
258 * filter: function(string, Function):angular.Module,
260 * init: function(Function):angular.Module