2 * @license AngularJS v0.10.6
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 {@link angular.directive.ng:app ng:app} or
63 * {@link angular.bootstrap} to simplify this process for you.
65 * @param {!string} name The name of the module to create or retrieve.
66 * @param {Array.<string>=} requires If specified then new module is being created. If unspecified then the
67 * the module is being retrieved for further configuration.
68 * @param {Function} configFn Option configuration function for the module. Same as
69 * {@link angular.Module#config Module#config()}.
70 * @returns {module} new module with the {@link angular.Module} api.
72 return function module(name, requires, configFn) {
73 if (requires && modules.hasOwnProperty(name)) {
76 return ensure(modules, name, function() {
78 throw Error('No module: ' + name);
81 /** @type {!Array.<Array.<*>>} */
84 /** @type {!Array.<Function>} */
87 var config = invokeLater('$injector', 'invoke');
89 /** @type {angular.Module} */
90 var moduleInstance = {
92 _invokeQueue: invokeQueue,
93 _runBlocks: runBlocks,
97 * @name angular.Module#requires
98 * @propertyOf angular.Module
99 * @returns {Array.<string>} List of module names which must be loaded before this module.
101 * Holds the list of modules which the injector will load before the current module is loaded.
107 * @name angular.Module#name
108 * @propertyOf angular.Module
109 * @returns {string} Name of the module.
117 * @name angular.Module#service
118 * @methodOf angular.Module
119 * @param {string} name service name
120 * @param {Function} providerType Construction function for creating new instance of the service.
122 * See {@link angular.module.AUTO.$provide#service $provide.service()}.
124 service: invokeLater('$provide', 'service'),
128 * @name angular.Module#factory
129 * @methodOf angular.Module
130 * @param {string} name service name
131 * @param {Function} providerFunction Function for creating new instance of the service.
133 * See {@link angular.module.AUTO.$provide#service $provide.factory()}.
135 factory: invokeLater('$provide', 'factory'),
139 * @name angular.Module#value
140 * @methodOf angular.Module
141 * @param {string} name service name
142 * @param {*} object Service instance object.
144 * See {@link angular.module.AUTO.$provide#value $provide.value()}.
146 value: invokeLater('$provide', 'value'),
150 * @name angular.Module#filter
151 * @methodOf angular.Module
152 * @param {string} name filterr name
153 * @param {Function} filterFactory Factory function for creating new instance of filter.
155 * See {@link angular.module.ng.$filterProvider#register $filterProvider.register()}.
157 filter: invokeLater('$filterProvider', 'register'),
161 * @name angular.Module#config
162 * @methodOf angular.Module
163 * @param {Function} configFn Execute this function on module load. Useful for service
166 * Use this method to register work which needs to be performed on module loading.
172 * @name angular.Module#run
173 * @methodOf angular.Module
174 * @param {Function} initializationFn Execute this function after injector creation.
175 * Useful for application initialization.
177 * Use this method to register work which needs to be performed when the injector with
178 * with the current module is finished loading.
180 run: function(block) {
181 runBlocks.push(block);
190 return moduleInstance;
193 * @param {string} provider
194 * @param {string} method
195 * @returns {angular.Module}
197 function invokeLater(provider, method) {
199 invokeQueue.push([provider, method, arguments]);
200 return moduleInstance;
211 * Closure compiler type information
214 * requires: !Array.<string>,
215 * invokeQueue: !Array.<Array.<*>>,
217 * service: function(string, Function):angular.Module,
218 * factory: function(string, Function):angular.Module,
219 * value: function(string, *):angular.Module,
221 * filter: function(string, Function):angular.Module,
223 * init: function(Function):angular.Module