2 * @license AngularJS v1.5.0
3 * (c) 2010-2016 Google, Inc. http://angularjs.org
7 (function() {'use strict';
8 function isFunction(value) {return typeof value === 'function';};
10 /* global: toDebugString: true */
12 function serializeObject(obj) {
15 return JSON.stringify(obj, function(key, val) {
16 val = toJsonReplacer(key, val);
19 if (seen.indexOf(val) >= 0) return '...';
27 function toDebugString(obj) {
28 if (typeof obj === 'function') {
29 return obj.toString().replace(/ \{[\s\S]*$/, '');
30 } else if (isUndefined(obj)) {
32 } else if (typeof obj !== 'string') {
33 return serializeObject(obj);
41 * This object provides a utility for producing rich Error messages within
42 * Angular. It can be called as follows:
44 * var exampleMinErr = minErr('example');
45 * throw exampleMinErr('one', 'This {0} is {1}', foo, bar);
47 * The above creates an instance of minErr in the example namespace. The
48 * resulting error will have a namespaced error code of example.one. The
49 * resulting error will replace {0} with the value of foo, and {1} with the
50 * value of bar. The object is not restricted in the number of arguments it can
53 * If fewer arguments are specified than necessary for interpolation, the extra
54 * interpolation markers will be preserved in the final string.
56 * Since data will be parsed statically during a build step, some restrictions
57 * are applied with respect to how minErr instances are created and called.
58 * Instances should have names of the form namespaceMinErr for a minErr created
59 * using minErr('namespace') . Error codes, namespaces and template strings
60 * should all be static strings, not variables or general expressions.
62 * @param {string} module The namespace to use for the new minErr instance.
63 * @param {function} ErrorConstructor Custom error constructor to be instantiated when returning
64 * error from returned function, for cases when a particular type of error is useful.
65 * @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance
68 function minErr(module, ErrorConstructor) {
69 ErrorConstructor = ErrorConstructor || Error;
73 var templateArgs = arguments,
74 code = templateArgs[0],
75 message = '[' + (module ? module + ':' : '') + code + '] ',
76 template = templateArgs[1],
79 message += template.replace(/\{\d+\}/g, function(match) {
80 var index = +match.slice(1, -1),
81 shiftedIndex = index + SKIP_INDEXES;
83 if (shiftedIndex < templateArgs.length) {
84 return toDebugString(templateArgs[shiftedIndex]);
90 message += '\nhttp://errors.angularjs.org/1.5.0/' +
91 (module ? module + '/' : '') + code;
93 for (i = SKIP_INDEXES, paramPrefix = '?'; i < templateArgs.length; i++, paramPrefix = '&') {
94 message += paramPrefix + 'p' + (i - SKIP_INDEXES) + '=' +
95 encodeURIComponent(toDebugString(templateArgs[i]));
98 return new ErrorConstructor(message);
104 * @name angular.Module
108 * Interface for configuring angular {@link angular.module modules}.
111 function setupModuleLoader(window) {
113 var $injectorMinErr = minErr('$injector');
114 var ngMinErr = minErr('ng');
116 function ensure(obj, name, factory) {
117 return obj[name] || (obj[name] = factory());
120 var angular = ensure(window, 'angular', Object);
122 // We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap
123 angular.$$minErr = angular.$$minErr || minErr;
125 return ensure(angular, 'module', function() {
126 /** @type {Object.<string, angular.Module>} */
131 * @name angular.module
135 * The `angular.module` is a global place for creating, registering and retrieving Angular
137 * All modules (angular core or 3rd party) that should be available to an application must be
138 * registered using this mechanism.
140 * Passing one argument retrieves an existing {@link angular.Module},
141 * whereas passing more than one argument creates a new {@link angular.Module}
146 * A module is a collection of services, directives, controllers, filters, and configuration information.
147 * `angular.module` is used to configure the {@link auto.$injector $injector}.
150 * // Create a new module
151 * var myModule = angular.module('myModule', []);
153 * // register a new service
154 * myModule.value('appName', 'MyCoolApp');
156 * // configure existing services inside initialization blocks.
157 * myModule.config(['$locationProvider', function($locationProvider) {
158 * // Configure existing providers
159 * $locationProvider.hashPrefix('!');
163 * Then you can create an injector and load your modules like this:
166 * var injector = angular.injector(['ng', 'myModule'])
169 * However it's more likely that you'll just use
170 * {@link ng.directive:ngApp ngApp} or
171 * {@link angular.bootstrap} to simplify this process for you.
173 * @param {!string} name The name of the module to create or retrieve.
174 * @param {!Array.<string>=} requires If specified then new module is being created. If
175 * unspecified then the module is being retrieved for further configuration.
176 * @param {Function=} configFn Optional configuration function for the module. Same as
177 * {@link angular.Module#config Module#config()}.
178 * @returns {angular.Module} new module with the {@link angular.Module} api.
180 return function module(name, requires, configFn) {
181 var assertNotHasOwnProperty = function(name, context) {
182 if (name === 'hasOwnProperty') {
183 throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context);
187 assertNotHasOwnProperty(name, 'module');
188 if (requires && modules.hasOwnProperty(name)) {
189 modules[name] = null;
191 return ensure(modules, name, function() {
193 throw $injectorMinErr('nomod', "Module '{0}' is not available! You either misspelled " +
194 "the module name or forgot to load it. If registering a module ensure that you " +
195 "specify the dependencies as the second argument.", name);
198 /** @type {!Array.<Array.<*>>} */
199 var invokeQueue = [];
201 /** @type {!Array.<Function>} */
202 var configBlocks = [];
204 /** @type {!Array.<Function>} */
207 var config = invokeLater('$injector', 'invoke', 'push', configBlocks);
209 /** @type {angular.Module} */
210 var moduleInstance = {
212 _invokeQueue: invokeQueue,
213 _configBlocks: configBlocks,
214 _runBlocks: runBlocks,
218 * @name angular.Module#requires
222 * Holds the list of modules which the injector will load before the current module is
229 * @name angular.Module#name
233 * Name of the module.
240 * @name angular.Module#provider
242 * @param {string} name service name
243 * @param {Function} providerType Construction function for creating new instance of the
246 * See {@link auto.$provide#provider $provide.provider()}.
248 provider: invokeLaterAndSetModuleName('$provide', 'provider'),
252 * @name angular.Module#factory
254 * @param {string} name service name
255 * @param {Function} providerFunction Function for creating new instance of the service.
257 * See {@link auto.$provide#factory $provide.factory()}.
259 factory: invokeLaterAndSetModuleName('$provide', 'factory'),
263 * @name angular.Module#service
265 * @param {string} name service name
266 * @param {Function} constructor A constructor function that will be instantiated.
268 * See {@link auto.$provide#service $provide.service()}.
270 service: invokeLaterAndSetModuleName('$provide', 'service'),
274 * @name angular.Module#value
276 * @param {string} name service name
277 * @param {*} object Service instance object.
279 * See {@link auto.$provide#value $provide.value()}.
281 value: invokeLater('$provide', 'value'),
285 * @name angular.Module#constant
287 * @param {string} name constant name
288 * @param {*} object Constant value.
290 * Because the constants are fixed, they get applied before other provide methods.
291 * See {@link auto.$provide#constant $provide.constant()}.
293 constant: invokeLater('$provide', 'constant', 'unshift'),
297 * @name angular.Module#decorator
299 * @param {string} The name of the service to decorate.
300 * @param {Function} This function will be invoked when the service needs to be
301 * instantiated and should return the decorated service instance.
303 * See {@link auto.$provide#decorator $provide.decorator()}.
305 decorator: invokeLaterAndSetModuleName('$provide', 'decorator'),
309 * @name angular.Module#animation
311 * @param {string} name animation name
312 * @param {Function} animationFactory Factory function for creating new instance of an
316 * **NOTE**: animations take effect only if the **ngAnimate** module is loaded.
319 * Defines an animation hook that can be later used with
320 * {@link $animate $animate} service and directives that use this service.
323 * module.animation('.animation-name', function($inject1, $inject2) {
325 * eventName : function(element, done) {
326 * //code to run the animation
327 * //once complete, then run done()
328 * return function cancellationFunction(element) {
329 * //code to cancel the animation
336 * See {@link ng.$animateProvider#register $animateProvider.register()} and
337 * {@link ngAnimate ngAnimate module} for more information.
339 animation: invokeLaterAndSetModuleName('$animateProvider', 'register'),
343 * @name angular.Module#filter
345 * @param {string} name Filter name - this must be a valid angular expression identifier
346 * @param {Function} filterFactory Factory function for creating new instance of filter.
348 * See {@link ng.$filterProvider#register $filterProvider.register()}.
350 * <div class="alert alert-warning">
351 * **Note:** Filter names must be valid angular {@link expression} identifiers, such as `uppercase` or `orderBy`.
352 * Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace
353 * your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores
354 * (`myapp_subsection_filterx`).
357 filter: invokeLaterAndSetModuleName('$filterProvider', 'register'),
361 * @name angular.Module#controller
363 * @param {string|Object} name Controller name, or an object map of controllers where the
364 * keys are the names and the values are the constructors.
365 * @param {Function} constructor Controller constructor function.
367 * See {@link ng.$controllerProvider#register $controllerProvider.register()}.
369 controller: invokeLaterAndSetModuleName('$controllerProvider', 'register'),
373 * @name angular.Module#directive
375 * @param {string|Object} name Directive name, or an object map of directives where the
376 * keys are the names and the values are the factories.
377 * @param {Function} directiveFactory Factory function for creating new instance of
380 * See {@link ng.$compileProvider#directive $compileProvider.directive()}.
382 directive: invokeLaterAndSetModuleName('$compileProvider', 'directive'),
386 * @name angular.Module#component
388 * @param {string} name Name of the component in camel-case (i.e. myComp which will match as my-comp)
389 * @param {Object} options Component definition object (a simplified
390 * {@link ng.$compile#directive-definition-object directive definition object})
393 * See {@link ng.$compileProvider#component $compileProvider.component()}.
395 component: invokeLaterAndSetModuleName('$compileProvider', 'component'),
399 * @name angular.Module#config
401 * @param {Function} configFn Execute this function on module load. Useful for service
404 * Use this method to register work which needs to be performed on module loading.
405 * For more about how to configure services, see
406 * {@link providers#provider-recipe Provider Recipe}.
412 * @name angular.Module#run
414 * @param {Function} initializationFn Execute this function after injector creation.
415 * Useful for application initialization.
417 * Use this method to register work which should be performed when the injector is done
418 * loading all modules.
420 run: function(block) {
421 runBlocks.push(block);
430 return moduleInstance;
433 * @param {string} provider
434 * @param {string} method
435 * @param {String=} insertMethod
436 * @returns {angular.Module}
438 function invokeLater(provider, method, insertMethod, queue) {
439 if (!queue) queue = invokeQueue;
441 queue[insertMethod || 'push']([provider, method, arguments]);
442 return moduleInstance;
447 * @param {string} provider
448 * @param {string} method
449 * @returns {angular.Module}
451 function invokeLaterAndSetModuleName(provider, method) {
452 return function(recipeName, factoryFunction) {
453 if (factoryFunction && isFunction(factoryFunction)) factoryFunction.$$moduleName = name;
454 invokeQueue.push([provider, method, arguments]);
455 return moduleInstance;
464 setupModuleLoader(window);
468 * Closure compiler type information
471 * requires: !Array.<string>,
472 * invokeQueue: !Array.<Array.<*>>,
474 * service: function(string, Function):angular.Module,
475 * factory: function(string, Function):angular.Module,
476 * value: function(string, *):angular.Module,
478 * filter: function(string, Function):angular.Module,
480 * init: function(Function):angular.Module