| @@ 193-587 (lines=395) @@ | ||
| 190 | * Interface for configuring angular {@link angular.module modules}. |
|
| 191 | */ |
|
| 192 | ||
| 193 | function setupModuleLoader(window) { |
|
| 194 | ||
| 195 | var $injectorMinErr = minErr('$injector'); |
|
| 196 | var ngMinErr = minErr('ng'); |
|
| 197 | ||
| 198 | function ensure(obj, name, factory) { |
|
| 199 | return obj[name] || (obj[name] = factory()); |
|
| 200 | } |
|
| 201 | ||
| 202 | var angular = ensure(window, 'angular', Object); |
|
| 203 | ||
| 204 | // We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap |
|
| 205 | angular.$$minErr = angular.$$minErr || minErr; |
|
| 206 | ||
| 207 | return ensure(angular, 'module', function() { |
|
| 208 | /** @type {Object.<string, angular.Module>} */ |
|
| 209 | var modules = {}; |
|
| 210 | ||
| 211 | /** |
|
| 212 | * @ngdoc function |
|
| 213 | * @name angular.module |
|
| 214 | * @module ng |
|
| 215 | * @description |
|
| 216 | * |
|
| 217 | * The `angular.module` is a global place for creating, registering and retrieving Angular |
|
| 218 | * modules. |
|
| 219 | * All modules (angular core or 3rd party) that should be available to an application must be |
|
| 220 | * registered using this mechanism. |
|
| 221 | * |
|
| 222 | * Passing one argument retrieves an existing {@link angular.Module}, |
|
| 223 | * whereas passing more than one argument creates a new {@link angular.Module} |
|
| 224 | * |
|
| 225 | * |
|
| 226 | * # Module |
|
| 227 | * |
|
| 228 | * A module is a collection of services, directives, controllers, filters, and configuration information. |
|
| 229 | * `angular.module` is used to configure the {@link auto.$injector $injector}. |
|
| 230 | * |
|
| 231 | * ```js |
|
| 232 | * // Create a new module |
|
| 233 | * var myModule = angular.module('myModule', []); |
|
| 234 | * |
|
| 235 | * // register a new service |
|
| 236 | * myModule.value('appName', 'MyCoolApp'); |
|
| 237 | * |
|
| 238 | * // configure existing services inside initialization blocks. |
|
| 239 | * myModule.config(['$locationProvider', function($locationProvider) { |
|
| 240 | * // Configure existing providers |
|
| 241 | * $locationProvider.hashPrefix('!'); |
|
| 242 | * }]); |
|
| 243 | * ``` |
|
| 244 | * |
|
| 245 | * Then you can create an injector and load your modules like this: |
|
| 246 | * |
|
| 247 | * ```js |
|
| 248 | * var injector = angular.injector(['ng', 'myModule']) |
|
| 249 | * ``` |
|
| 250 | * |
|
| 251 | * However it's more likely that you'll just use |
|
| 252 | * {@link ng.directive:ngApp ngApp} or |
|
| 253 | * {@link angular.bootstrap} to simplify this process for you. |
|
| 254 | * |
|
| 255 | * @param {!string} name The name of the module to create or retrieve. |
|
| 256 | * @param {!Array.<string>=} requires If specified then new module is being created. If |
|
| 257 | * unspecified then the module is being retrieved for further configuration. |
|
| 258 | * @param {Function=} configFn Optional configuration function for the module. Same as |
|
| 259 | * {@link angular.Module#config Module#config()}. |
|
| 260 | * @returns {angular.Module} new module with the {@link angular.Module} api. |
|
| 261 | */ |
|
| 262 | return function module(name, requires, configFn) { |
|
| 263 | ||
| 264 | var info = {}; |
|
| 265 | ||
| 266 | var assertNotHasOwnProperty = function(name, context) { |
|
| 267 | if (name === 'hasOwnProperty') { |
|
| 268 | throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context); |
|
| 269 | } |
|
| 270 | }; |
|
| 271 | ||
| 272 | assertNotHasOwnProperty(name, 'module'); |
|
| 273 | if (requires && modules.hasOwnProperty(name)) { |
|
| 274 | modules[name] = null; |
|
| 275 | } |
|
| 276 | return ensure(modules, name, function() { |
|
| 277 | if (!requires) { |
|
| 278 | throw $injectorMinErr('nomod', 'Module \'{0}\' is not available! You either misspelled ' + |
|
| 279 | 'the module name or forgot to load it. If registering a module ensure that you ' + |
|
| 280 | 'specify the dependencies as the second argument.', name); |
|
| 281 | } |
|
| 282 | ||
| 283 | /** @type {!Array.<Array.<*>>} */ |
|
| 284 | var invokeQueue = []; |
|
| 285 | ||
| 286 | /** @type {!Array.<Function>} */ |
|
| 287 | var configBlocks = []; |
|
| 288 | ||
| 289 | /** @type {!Array.<Function>} */ |
|
| 290 | var runBlocks = []; |
|
| 291 | ||
| 292 | var config = invokeLater('$injector', 'invoke', 'push', configBlocks); |
|
| 293 | ||
| 294 | /** @type {angular.Module} */ |
|
| 295 | var moduleInstance = { |
|
| 296 | // Private state |
|
| 297 | _invokeQueue: invokeQueue, |
|
| 298 | _configBlocks: configBlocks, |
|
| 299 | _runBlocks: runBlocks, |
|
| 300 | ||
| 301 | /** |
|
| 302 | * @ngdoc method |
|
| 303 | * @name angular.Module#info |
|
| 304 | * @module ng |
|
| 305 | * |
|
| 306 | * @param {Object=} info Information about the module |
|
| 307 | * @returns {Object|Module} The current info object for this module if called as a getter, |
|
| 308 | * or `this` if called as a setter. |
|
| 309 | * |
|
| 310 | * @description |
|
| 311 | * Read and write custom information about this module. |
|
| 312 | * For example you could put the version of the module in here. |
|
| 313 | * |
|
| 314 | * ```js |
|
| 315 | * angular.module('myModule', []).info({ version: '1.0.0' }); |
|
| 316 | * ``` |
|
| 317 | * |
|
| 318 | * The version could then be read back out by accessing the module elsewhere: |
|
| 319 | * |
|
| 320 | * ``` |
|
| 321 | * var version = angular.module('myModule').info().version; |
|
| 322 | * ``` |
|
| 323 | * |
|
| 324 | * You can also retrieve this information during runtime via the |
|
| 325 | * {@link $injector#modules `$injector.modules`} property: |
|
| 326 | * |
|
| 327 | * ```js |
|
| 328 | * var version = $injector.modules['myModule'].info().version; |
|
| 329 | * ``` |
|
| 330 | */ |
|
| 331 | info: function(value) { |
|
| 332 | if (isDefined(value)) { |
|
| 333 | if (!isObject(value)) throw ngMinErr('aobj', 'Argument \'{0}\' must be an object', 'value'); |
|
| 334 | info = value; |
|
| 335 | return this; |
|
| 336 | } |
|
| 337 | return info; |
|
| 338 | }, |
|
| 339 | ||
| 340 | /** |
|
| 341 | * @ngdoc property |
|
| 342 | * @name angular.Module#requires |
|
| 343 | * @module ng |
|
| 344 | * |
|
| 345 | * @description |
|
| 346 | * Holds the list of modules which the injector will load before the current module is |
|
| 347 | * loaded. |
|
| 348 | */ |
|
| 349 | requires: requires, |
|
| 350 | ||
| 351 | /** |
|
| 352 | * @ngdoc property |
|
| 353 | * @name angular.Module#name |
|
| 354 | * @module ng |
|
| 355 | * |
|
| 356 | * @description |
|
| 357 | * Name of the module. |
|
| 358 | */ |
|
| 359 | name: name, |
|
| 360 | ||
| 361 | ||
| 362 | /** |
|
| 363 | * @ngdoc method |
|
| 364 | * @name angular.Module#provider |
|
| 365 | * @module ng |
|
| 366 | * @param {string} name service name |
|
| 367 | * @param {Function} providerType Construction function for creating new instance of the |
|
| 368 | * service. |
|
| 369 | * @description |
|
| 370 | * See {@link auto.$provide#provider $provide.provider()}. |
|
| 371 | */ |
|
| 372 | provider: invokeLaterAndSetModuleName('$provide', 'provider'), |
|
| 373 | ||
| 374 | /** |
|
| 375 | * @ngdoc method |
|
| 376 | * @name angular.Module#factory |
|
| 377 | * @module ng |
|
| 378 | * @param {string} name service name |
|
| 379 | * @param {Function} providerFunction Function for creating new instance of the service. |
|
| 380 | * @description |
|
| 381 | * See {@link auto.$provide#factory $provide.factory()}. |
|
| 382 | */ |
|
| 383 | factory: invokeLaterAndSetModuleName('$provide', 'factory'), |
|
| 384 | ||
| 385 | /** |
|
| 386 | * @ngdoc method |
|
| 387 | * @name angular.Module#service |
|
| 388 | * @module ng |
|
| 389 | * @param {string} name service name |
|
| 390 | * @param {Function} constructor A constructor function that will be instantiated. |
|
| 391 | * @description |
|
| 392 | * See {@link auto.$provide#service $provide.service()}. |
|
| 393 | */ |
|
| 394 | service: invokeLaterAndSetModuleName('$provide', 'service'), |
|
| 395 | ||
| 396 | /** |
|
| 397 | * @ngdoc method |
|
| 398 | * @name angular.Module#value |
|
| 399 | * @module ng |
|
| 400 | * @param {string} name service name |
|
| 401 | * @param {*} object Service instance object. |
|
| 402 | * @description |
|
| 403 | * See {@link auto.$provide#value $provide.value()}. |
|
| 404 | */ |
|
| 405 | value: invokeLater('$provide', 'value'), |
|
| 406 | ||
| 407 | /** |
|
| 408 | * @ngdoc method |
|
| 409 | * @name angular.Module#constant |
|
| 410 | * @module ng |
|
| 411 | * @param {string} name constant name |
|
| 412 | * @param {*} object Constant value. |
|
| 413 | * @description |
|
| 414 | * Because the constants are fixed, they get applied before other provide methods. |
|
| 415 | * See {@link auto.$provide#constant $provide.constant()}. |
|
| 416 | */ |
|
| 417 | constant: invokeLater('$provide', 'constant', 'unshift'), |
|
| 418 | ||
| 419 | /** |
|
| 420 | * @ngdoc method |
|
| 421 | * @name angular.Module#decorator |
|
| 422 | * @module ng |
|
| 423 | * @param {string} name The name of the service to decorate. |
|
| 424 | * @param {Function} decorFn This function will be invoked when the service needs to be |
|
| 425 | * instantiated and should return the decorated service instance. |
|
| 426 | * @description |
|
| 427 | * See {@link auto.$provide#decorator $provide.decorator()}. |
|
| 428 | */ |
|
| 429 | decorator: invokeLaterAndSetModuleName('$provide', 'decorator', configBlocks), |
|
| 430 | ||
| 431 | /** |
|
| 432 | * @ngdoc method |
|
| 433 | * @name angular.Module#animation |
|
| 434 | * @module ng |
|
| 435 | * @param {string} name animation name |
|
| 436 | * @param {Function} animationFactory Factory function for creating new instance of an |
|
| 437 | * animation. |
|
| 438 | * @description |
|
| 439 | * |
|
| 440 | * **NOTE**: animations take effect only if the **ngAnimate** module is loaded. |
|
| 441 | * |
|
| 442 | * |
|
| 443 | * Defines an animation hook that can be later used with |
|
| 444 | * {@link $animate $animate} service and directives that use this service. |
|
| 445 | * |
|
| 446 | * ```js |
|
| 447 | * module.animation('.animation-name', function($inject1, $inject2) { |
|
| 448 | * return { |
|
| 449 | * eventName : function(element, done) { |
|
| 450 | * //code to run the animation |
|
| 451 | * //once complete, then run done() |
|
| 452 | * return function cancellationFunction(element) { |
|
| 453 | * //code to cancel the animation |
|
| 454 | * } |
|
| 455 | * } |
|
| 456 | * } |
|
| 457 | * }) |
|
| 458 | * ``` |
|
| 459 | * |
|
| 460 | * See {@link ng.$animateProvider#register $animateProvider.register()} and |
|
| 461 | * {@link ngAnimate ngAnimate module} for more information. |
|
| 462 | */ |
|
| 463 | animation: invokeLaterAndSetModuleName('$animateProvider', 'register'), |
|
| 464 | ||
| 465 | /** |
|
| 466 | * @ngdoc method |
|
| 467 | * @name angular.Module#filter |
|
| 468 | * @module ng |
|
| 469 | * @param {string} name Filter name - this must be a valid angular expression identifier |
|
| 470 | * @param {Function} filterFactory Factory function for creating new instance of filter. |
|
| 471 | * @description |
|
| 472 | * See {@link ng.$filterProvider#register $filterProvider.register()}. |
|
| 473 | * |
|
| 474 | * <div class="alert alert-warning"> |
|
| 475 | * **Note:** Filter names must be valid angular {@link expression} identifiers, such as `uppercase` or `orderBy`. |
|
| 476 | * Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace |
|
| 477 | * your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores |
|
| 478 | * (`myapp_subsection_filterx`). |
|
| 479 | * </div> |
|
| 480 | */ |
|
| 481 | filter: invokeLaterAndSetModuleName('$filterProvider', 'register'), |
|
| 482 | ||
| 483 | /** |
|
| 484 | * @ngdoc method |
|
| 485 | * @name angular.Module#controller |
|
| 486 | * @module ng |
|
| 487 | * @param {string|Object} name Controller name, or an object map of controllers where the |
|
| 488 | * keys are the names and the values are the constructors. |
|
| 489 | * @param {Function} constructor Controller constructor function. |
|
| 490 | * @description |
|
| 491 | * See {@link ng.$controllerProvider#register $controllerProvider.register()}. |
|
| 492 | */ |
|
| 493 | controller: invokeLaterAndSetModuleName('$controllerProvider', 'register'), |
|
| 494 | ||
| 495 | /** |
|
| 496 | * @ngdoc method |
|
| 497 | * @name angular.Module#directive |
|
| 498 | * @module ng |
|
| 499 | * @param {string|Object} name Directive name, or an object map of directives where the |
|
| 500 | * keys are the names and the values are the factories. |
|
| 501 | * @param {Function} directiveFactory Factory function for creating new instance of |
|
| 502 | * directives. |
|
| 503 | * @description |
|
| 504 | * See {@link ng.$compileProvider#directive $compileProvider.directive()}. |
|
| 505 | */ |
|
| 506 | directive: invokeLaterAndSetModuleName('$compileProvider', 'directive'), |
|
| 507 | ||
| 508 | /** |
|
| 509 | * @ngdoc method |
|
| 510 | * @name angular.Module#component |
|
| 511 | * @module ng |
|
| 512 | * @param {string} name Name of the component in camel-case (i.e. myComp which will match as my-comp) |
|
| 513 | * @param {Object} options Component definition object (a simplified |
|
| 514 | * {@link ng.$compile#directive-definition-object directive definition object}) |
|
| 515 | * |
|
| 516 | * @description |
|
| 517 | * See {@link ng.$compileProvider#component $compileProvider.component()}. |
|
| 518 | */ |
|
| 519 | component: invokeLaterAndSetModuleName('$compileProvider', 'component'), |
|
| 520 | ||
| 521 | /** |
|
| 522 | * @ngdoc method |
|
| 523 | * @name angular.Module#config |
|
| 524 | * @module ng |
|
| 525 | * @param {Function} configFn Execute this function on module load. Useful for service |
|
| 526 | * configuration. |
|
| 527 | * @description |
|
| 528 | * Use this method to register work which needs to be performed on module loading. |
|
| 529 | * For more about how to configure services, see |
|
| 530 | * {@link providers#provider-recipe Provider Recipe}. |
|
| 531 | */ |
|
| 532 | config: config, |
|
| 533 | ||
| 534 | /** |
|
| 535 | * @ngdoc method |
|
| 536 | * @name angular.Module#run |
|
| 537 | * @module ng |
|
| 538 | * @param {Function} initializationFn Execute this function after injector creation. |
|
| 539 | * Useful for application initialization. |
|
| 540 | * @description |
|
| 541 | * Use this method to register work which should be performed when the injector is done |
|
| 542 | * loading all modules. |
|
| 543 | */ |
|
| 544 | run: function(block) { |
|
| 545 | runBlocks.push(block); |
|
| 546 | return this; |
|
| 547 | } |
|
| 548 | }; |
|
| 549 | ||
| 550 | if (configFn) { |
|
| 551 | config(configFn); |
|
| 552 | } |
|
| 553 | ||
| 554 | return moduleInstance; |
|
| 555 | ||
| 556 | /** |
|
| 557 | * @param {string} provider |
|
| 558 | * @param {string} method |
|
| 559 | * @param {String=} insertMethod |
|
| 560 | * @returns {angular.Module} |
|
| 561 | */ |
|
| 562 | function invokeLater(provider, method, insertMethod, queue) { |
|
| 563 | if (!queue) queue = invokeQueue; |
|
| 564 | return function() { |
|
| 565 | queue[insertMethod || 'push']([provider, method, arguments]); |
|
| 566 | return moduleInstance; |
|
| 567 | }; |
|
| 568 | } |
|
| 569 | ||
| 570 | /** |
|
| 571 | * @param {string} provider |
|
| 572 | * @param {string} method |
|
| 573 | * @returns {angular.Module} |
|
| 574 | */ |
|
| 575 | function invokeLaterAndSetModuleName(provider, method, queue) { |
|
| 576 | if (!queue) queue = invokeQueue; |
|
| 577 | return function(recipeName, factoryFunction) { |
|
| 578 | if (factoryFunction && isFunction(factoryFunction)) factoryFunction.$$moduleName = name; |
|
| 579 | queue.push([provider, method, arguments]); |
|
| 580 | return moduleInstance; |
|
| 581 | }; |
|
| 582 | } |
|
| 583 | }); |
|
| 584 | }; |
|
| 585 | }); |
|
| 586 | ||
| 587 | } |
|
| 588 | ||
| 589 | setupModuleLoader(window); |
|
| 590 | })(window); |
|
| @@ 117-511 (lines=395) @@ | ||
| 114 | * Interface for configuring angular {@link angular.module modules}. |
|
| 115 | */ |
|
| 116 | ||
| 117 | function setupModuleLoader(window) { |
|
| 118 | ||
| 119 | var $injectorMinErr = minErr('$injector'); |
|
| 120 | var ngMinErr = minErr('ng'); |
|
| 121 | ||
| 122 | function ensure(obj, name, factory) { |
|
| 123 | return obj[name] || (obj[name] = factory()); |
|
| 124 | } |
|
| 125 | ||
| 126 | var angular = ensure(window, 'angular', Object); |
|
| 127 | ||
| 128 | // We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap |
|
| 129 | angular.$$minErr = angular.$$minErr || minErr; |
|
| 130 | ||
| 131 | return ensure(angular, 'module', function() { |
|
| 132 | /** @type {Object.<string, angular.Module>} */ |
|
| 133 | var modules = {}; |
|
| 134 | ||
| 135 | /** |
|
| 136 | * @ngdoc function |
|
| 137 | * @name angular.module |
|
| 138 | * @module ng |
|
| 139 | * @description |
|
| 140 | * |
|
| 141 | * The `angular.module` is a global place for creating, registering and retrieving Angular |
|
| 142 | * modules. |
|
| 143 | * All modules (angular core or 3rd party) that should be available to an application must be |
|
| 144 | * registered using this mechanism. |
|
| 145 | * |
|
| 146 | * Passing one argument retrieves an existing {@link angular.Module}, |
|
| 147 | * whereas passing more than one argument creates a new {@link angular.Module} |
|
| 148 | * |
|
| 149 | * |
|
| 150 | * # Module |
|
| 151 | * |
|
| 152 | * A module is a collection of services, directives, controllers, filters, and configuration information. |
|
| 153 | * `angular.module` is used to configure the {@link auto.$injector $injector}. |
|
| 154 | * |
|
| 155 | * ```js |
|
| 156 | * // Create a new module |
|
| 157 | * var myModule = angular.module('myModule', []); |
|
| 158 | * |
|
| 159 | * // register a new service |
|
| 160 | * myModule.value('appName', 'MyCoolApp'); |
|
| 161 | * |
|
| 162 | * // configure existing services inside initialization blocks. |
|
| 163 | * myModule.config(['$locationProvider', function($locationProvider) { |
|
| 164 | * // Configure existing providers |
|
| 165 | * $locationProvider.hashPrefix('!'); |
|
| 166 | * }]); |
|
| 167 | * ``` |
|
| 168 | * |
|
| 169 | * Then you can create an injector and load your modules like this: |
|
| 170 | * |
|
| 171 | * ```js |
|
| 172 | * var injector = angular.injector(['ng', 'myModule']) |
|
| 173 | * ``` |
|
| 174 | * |
|
| 175 | * However it's more likely that you'll just use |
|
| 176 | * {@link ng.directive:ngApp ngApp} or |
|
| 177 | * {@link angular.bootstrap} to simplify this process for you. |
|
| 178 | * |
|
| 179 | * @param {!string} name The name of the module to create or retrieve. |
|
| 180 | * @param {!Array.<string>=} requires If specified then new module is being created. If |
|
| 181 | * unspecified then the module is being retrieved for further configuration. |
|
| 182 | * @param {Function=} configFn Optional configuration function for the module. Same as |
|
| 183 | * {@link angular.Module#config Module#config()}. |
|
| 184 | * @returns {angular.Module} new module with the {@link angular.Module} api. |
|
| 185 | */ |
|
| 186 | return function module(name, requires, configFn) { |
|
| 187 | ||
| 188 | var info = {}; |
|
| 189 | ||
| 190 | var assertNotHasOwnProperty = function(name, context) { |
|
| 191 | if (name === 'hasOwnProperty') { |
|
| 192 | throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context); |
|
| 193 | } |
|
| 194 | }; |
|
| 195 | ||
| 196 | assertNotHasOwnProperty(name, 'module'); |
|
| 197 | if (requires && modules.hasOwnProperty(name)) { |
|
| 198 | modules[name] = null; |
|
| 199 | } |
|
| 200 | return ensure(modules, name, function() { |
|
| 201 | if (!requires) { |
|
| 202 | throw $injectorMinErr('nomod', 'Module \'{0}\' is not available! You either misspelled ' + |
|
| 203 | 'the module name or forgot to load it. If registering a module ensure that you ' + |
|
| 204 | 'specify the dependencies as the second argument.', name); |
|
| 205 | } |
|
| 206 | ||
| 207 | /** @type {!Array.<Array.<*>>} */ |
|
| 208 | var invokeQueue = []; |
|
| 209 | ||
| 210 | /** @type {!Array.<Function>} */ |
|
| 211 | var configBlocks = []; |
|
| 212 | ||
| 213 | /** @type {!Array.<Function>} */ |
|
| 214 | var runBlocks = []; |
|
| 215 | ||
| 216 | var config = invokeLater('$injector', 'invoke', 'push', configBlocks); |
|
| 217 | ||
| 218 | /** @type {angular.Module} */ |
|
| 219 | var moduleInstance = { |
|
| 220 | // Private state |
|
| 221 | _invokeQueue: invokeQueue, |
|
| 222 | _configBlocks: configBlocks, |
|
| 223 | _runBlocks: runBlocks, |
|
| 224 | ||
| 225 | /** |
|
| 226 | * @ngdoc method |
|
| 227 | * @name angular.Module#info |
|
| 228 | * @module ng |
|
| 229 | * |
|
| 230 | * @param {Object=} info Information about the module |
|
| 231 | * @returns {Object|Module} The current info object for this module if called as a getter, |
|
| 232 | * or `this` if called as a setter. |
|
| 233 | * |
|
| 234 | * @description |
|
| 235 | * Read and write custom information about this module. |
|
| 236 | * For example you could put the version of the module in here. |
|
| 237 | * |
|
| 238 | * ```js |
|
| 239 | * angular.module('myModule', []).info({ version: '1.0.0' }); |
|
| 240 | * ``` |
|
| 241 | * |
|
| 242 | * The version could then be read back out by accessing the module elsewhere: |
|
| 243 | * |
|
| 244 | * ``` |
|
| 245 | * var version = angular.module('myModule').info().version; |
|
| 246 | * ``` |
|
| 247 | * |
|
| 248 | * You can also retrieve this information during runtime via the |
|
| 249 | * {@link $injector#modules `$injector.modules`} property: |
|
| 250 | * |
|
| 251 | * ```js |
|
| 252 | * var version = $injector.modules['myModule'].info().version; |
|
| 253 | * ``` |
|
| 254 | */ |
|
| 255 | info: function(value) { |
|
| 256 | if (isDefined(value)) { |
|
| 257 | if (!isObject(value)) throw ngMinErr('aobj', 'Argument \'{0}\' must be an object', 'value'); |
|
| 258 | info = value; |
|
| 259 | return this; |
|
| 260 | } |
|
| 261 | return info; |
|
| 262 | }, |
|
| 263 | ||
| 264 | /** |
|
| 265 | * @ngdoc property |
|
| 266 | * @name angular.Module#requires |
|
| 267 | * @module ng |
|
| 268 | * |
|
| 269 | * @description |
|
| 270 | * Holds the list of modules which the injector will load before the current module is |
|
| 271 | * loaded. |
|
| 272 | */ |
|
| 273 | requires: requires, |
|
| 274 | ||
| 275 | /** |
|
| 276 | * @ngdoc property |
|
| 277 | * @name angular.Module#name |
|
| 278 | * @module ng |
|
| 279 | * |
|
| 280 | * @description |
|
| 281 | * Name of the module. |
|
| 282 | */ |
|
| 283 | name: name, |
|
| 284 | ||
| 285 | ||
| 286 | /** |
|
| 287 | * @ngdoc method |
|
| 288 | * @name angular.Module#provider |
|
| 289 | * @module ng |
|
| 290 | * @param {string} name service name |
|
| 291 | * @param {Function} providerType Construction function for creating new instance of the |
|
| 292 | * service. |
|
| 293 | * @description |
|
| 294 | * See {@link auto.$provide#provider $provide.provider()}. |
|
| 295 | */ |
|
| 296 | provider: invokeLaterAndSetModuleName('$provide', 'provider'), |
|
| 297 | ||
| 298 | /** |
|
| 299 | * @ngdoc method |
|
| 300 | * @name angular.Module#factory |
|
| 301 | * @module ng |
|
| 302 | * @param {string} name service name |
|
| 303 | * @param {Function} providerFunction Function for creating new instance of the service. |
|
| 304 | * @description |
|
| 305 | * See {@link auto.$provide#factory $provide.factory()}. |
|
| 306 | */ |
|
| 307 | factory: invokeLaterAndSetModuleName('$provide', 'factory'), |
|
| 308 | ||
| 309 | /** |
|
| 310 | * @ngdoc method |
|
| 311 | * @name angular.Module#service |
|
| 312 | * @module ng |
|
| 313 | * @param {string} name service name |
|
| 314 | * @param {Function} constructor A constructor function that will be instantiated. |
|
| 315 | * @description |
|
| 316 | * See {@link auto.$provide#service $provide.service()}. |
|
| 317 | */ |
|
| 318 | service: invokeLaterAndSetModuleName('$provide', 'service'), |
|
| 319 | ||
| 320 | /** |
|
| 321 | * @ngdoc method |
|
| 322 | * @name angular.Module#value |
|
| 323 | * @module ng |
|
| 324 | * @param {string} name service name |
|
| 325 | * @param {*} object Service instance object. |
|
| 326 | * @description |
|
| 327 | * See {@link auto.$provide#value $provide.value()}. |
|
| 328 | */ |
|
| 329 | value: invokeLater('$provide', 'value'), |
|
| 330 | ||
| 331 | /** |
|
| 332 | * @ngdoc method |
|
| 333 | * @name angular.Module#constant |
|
| 334 | * @module ng |
|
| 335 | * @param {string} name constant name |
|
| 336 | * @param {*} object Constant value. |
|
| 337 | * @description |
|
| 338 | * Because the constants are fixed, they get applied before other provide methods. |
|
| 339 | * See {@link auto.$provide#constant $provide.constant()}. |
|
| 340 | */ |
|
| 341 | constant: invokeLater('$provide', 'constant', 'unshift'), |
|
| 342 | ||
| 343 | /** |
|
| 344 | * @ngdoc method |
|
| 345 | * @name angular.Module#decorator |
|
| 346 | * @module ng |
|
| 347 | * @param {string} name The name of the service to decorate. |
|
| 348 | * @param {Function} decorFn This function will be invoked when the service needs to be |
|
| 349 | * instantiated and should return the decorated service instance. |
|
| 350 | * @description |
|
| 351 | * See {@link auto.$provide#decorator $provide.decorator()}. |
|
| 352 | */ |
|
| 353 | decorator: invokeLaterAndSetModuleName('$provide', 'decorator', configBlocks), |
|
| 354 | ||
| 355 | /** |
|
| 356 | * @ngdoc method |
|
| 357 | * @name angular.Module#animation |
|
| 358 | * @module ng |
|
| 359 | * @param {string} name animation name |
|
| 360 | * @param {Function} animationFactory Factory function for creating new instance of an |
|
| 361 | * animation. |
|
| 362 | * @description |
|
| 363 | * |
|
| 364 | * **NOTE**: animations take effect only if the **ngAnimate** module is loaded. |
|
| 365 | * |
|
| 366 | * |
|
| 367 | * Defines an animation hook that can be later used with |
|
| 368 | * {@link $animate $animate} service and directives that use this service. |
|
| 369 | * |
|
| 370 | * ```js |
|
| 371 | * module.animation('.animation-name', function($inject1, $inject2) { |
|
| 372 | * return { |
|
| 373 | * eventName : function(element, done) { |
|
| 374 | * //code to run the animation |
|
| 375 | * //once complete, then run done() |
|
| 376 | * return function cancellationFunction(element) { |
|
| 377 | * //code to cancel the animation |
|
| 378 | * } |
|
| 379 | * } |
|
| 380 | * } |
|
| 381 | * }) |
|
| 382 | * ``` |
|
| 383 | * |
|
| 384 | * See {@link ng.$animateProvider#register $animateProvider.register()} and |
|
| 385 | * {@link ngAnimate ngAnimate module} for more information. |
|
| 386 | */ |
|
| 387 | animation: invokeLaterAndSetModuleName('$animateProvider', 'register'), |
|
| 388 | ||
| 389 | /** |
|
| 390 | * @ngdoc method |
|
| 391 | * @name angular.Module#filter |
|
| 392 | * @module ng |
|
| 393 | * @param {string} name Filter name - this must be a valid angular expression identifier |
|
| 394 | * @param {Function} filterFactory Factory function for creating new instance of filter. |
|
| 395 | * @description |
|
| 396 | * See {@link ng.$filterProvider#register $filterProvider.register()}. |
|
| 397 | * |
|
| 398 | * <div class="alert alert-warning"> |
|
| 399 | * **Note:** Filter names must be valid angular {@link expression} identifiers, such as `uppercase` or `orderBy`. |
|
| 400 | * Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace |
|
| 401 | * your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores |
|
| 402 | * (`myapp_subsection_filterx`). |
|
| 403 | * </div> |
|
| 404 | */ |
|
| 405 | filter: invokeLaterAndSetModuleName('$filterProvider', 'register'), |
|
| 406 | ||
| 407 | /** |
|
| 408 | * @ngdoc method |
|
| 409 | * @name angular.Module#controller |
|
| 410 | * @module ng |
|
| 411 | * @param {string|Object} name Controller name, or an object map of controllers where the |
|
| 412 | * keys are the names and the values are the constructors. |
|
| 413 | * @param {Function} constructor Controller constructor function. |
|
| 414 | * @description |
|
| 415 | * See {@link ng.$controllerProvider#register $controllerProvider.register()}. |
|
| 416 | */ |
|
| 417 | controller: invokeLaterAndSetModuleName('$controllerProvider', 'register'), |
|
| 418 | ||
| 419 | /** |
|
| 420 | * @ngdoc method |
|
| 421 | * @name angular.Module#directive |
|
| 422 | * @module ng |
|
| 423 | * @param {string|Object} name Directive name, or an object map of directives where the |
|
| 424 | * keys are the names and the values are the factories. |
|
| 425 | * @param {Function} directiveFactory Factory function for creating new instance of |
|
| 426 | * directives. |
|
| 427 | * @description |
|
| 428 | * See {@link ng.$compileProvider#directive $compileProvider.directive()}. |
|
| 429 | */ |
|
| 430 | directive: invokeLaterAndSetModuleName('$compileProvider', 'directive'), |
|
| 431 | ||
| 432 | /** |
|
| 433 | * @ngdoc method |
|
| 434 | * @name angular.Module#component |
|
| 435 | * @module ng |
|
| 436 | * @param {string} name Name of the component in camel-case (i.e. myComp which will match as my-comp) |
|
| 437 | * @param {Object} options Component definition object (a simplified |
|
| 438 | * {@link ng.$compile#directive-definition-object directive definition object}) |
|
| 439 | * |
|
| 440 | * @description |
|
| 441 | * See {@link ng.$compileProvider#component $compileProvider.component()}. |
|
| 442 | */ |
|
| 443 | component: invokeLaterAndSetModuleName('$compileProvider', 'component'), |
|
| 444 | ||
| 445 | /** |
|
| 446 | * @ngdoc method |
|
| 447 | * @name angular.Module#config |
|
| 448 | * @module ng |
|
| 449 | * @param {Function} configFn Execute this function on module load. Useful for service |
|
| 450 | * configuration. |
|
| 451 | * @description |
|
| 452 | * Use this method to register work which needs to be performed on module loading. |
|
| 453 | * For more about how to configure services, see |
|
| 454 | * {@link providers#provider-recipe Provider Recipe}. |
|
| 455 | */ |
|
| 456 | config: config, |
|
| 457 | ||
| 458 | /** |
|
| 459 | * @ngdoc method |
|
| 460 | * @name angular.Module#run |
|
| 461 | * @module ng |
|
| 462 | * @param {Function} initializationFn Execute this function after injector creation. |
|
| 463 | * Useful for application initialization. |
|
| 464 | * @description |
|
| 465 | * Use this method to register work which should be performed when the injector is done |
|
| 466 | * loading all modules. |
|
| 467 | */ |
|
| 468 | run: function(block) { |
|
| 469 | runBlocks.push(block); |
|
| 470 | return this; |
|
| 471 | } |
|
| 472 | }; |
|
| 473 | ||
| 474 | if (configFn) { |
|
| 475 | config(configFn); |
|
| 476 | } |
|
| 477 | ||
| 478 | return moduleInstance; |
|
| 479 | ||
| 480 | /** |
|
| 481 | * @param {string} provider |
|
| 482 | * @param {string} method |
|
| 483 | * @param {String=} insertMethod |
|
| 484 | * @returns {angular.Module} |
|
| 485 | */ |
|
| 486 | function invokeLater(provider, method, insertMethod, queue) { |
|
| 487 | if (!queue) queue = invokeQueue; |
|
| 488 | return function() { |
|
| 489 | queue[insertMethod || 'push']([provider, method, arguments]); |
|
| 490 | return moduleInstance; |
|
| 491 | }; |
|
| 492 | } |
|
| 493 | ||
| 494 | /** |
|
| 495 | * @param {string} provider |
|
| 496 | * @param {string} method |
|
| 497 | * @returns {angular.Module} |
|
| 498 | */ |
|
| 499 | function invokeLaterAndSetModuleName(provider, method, queue) { |
|
| 500 | if (!queue) queue = invokeQueue; |
|
| 501 | return function(recipeName, factoryFunction) { |
|
| 502 | if (factoryFunction && isFunction(factoryFunction)) factoryFunction.$$moduleName = name; |
|
| 503 | queue.push([provider, method, arguments]); |
|
| 504 | return moduleInstance; |
|
| 505 | }; |
|
| 506 | } |
|
| 507 | }); |
|
| 508 | }; |
|
| 509 | }); |
|
| 510 | ||
| 511 | } |
|
| 512 | ||
| 513 | setupModuleLoader(window); |
|
| 514 | })(window); |
|
| @@ 111-462 (lines=352) @@ | ||
| 108 | * Interface for configuring angular {@link angular.module modules}. |
|
| 109 | */ |
|
| 110 | ||
| 111 | function setupModuleLoader(window) { |
|
| 112 | ||
| 113 | var $injectorMinErr = minErr('$injector'); |
|
| 114 | var ngMinErr = minErr('ng'); |
|
| 115 | ||
| 116 | function ensure(obj, name, factory) { |
|
| 117 | return obj[name] || (obj[name] = factory()); |
|
| 118 | } |
|
| 119 | ||
| 120 | var angular = ensure(window, 'angular', Object); |
|
| 121 | ||
| 122 | // We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap |
|
| 123 | angular.$$minErr = angular.$$minErr || minErr; |
|
| 124 | ||
| 125 | return ensure(angular, 'module', function() { |
|
| 126 | /** @type {Object.<string, angular.Module>} */ |
|
| 127 | var modules = {}; |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @ngdoc function |
|
| 131 | * @name angular.module |
|
| 132 | * @module ng |
|
| 133 | * @description |
|
| 134 | * |
|
| 135 | * The `angular.module` is a global place for creating, registering and retrieving Angular |
|
| 136 | * modules. |
|
| 137 | * All modules (angular core or 3rd party) that should be available to an application must be |
|
| 138 | * registered using this mechanism. |
|
| 139 | * |
|
| 140 | * Passing one argument retrieves an existing {@link angular.Module}, |
|
| 141 | * whereas passing more than one argument creates a new {@link angular.Module} |
|
| 142 | * |
|
| 143 | * |
|
| 144 | * # Module |
|
| 145 | * |
|
| 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}. |
|
| 148 | * |
|
| 149 | * ```js |
|
| 150 | * // Create a new module |
|
| 151 | * var myModule = angular.module('myModule', []); |
|
| 152 | * |
|
| 153 | * // register a new service |
|
| 154 | * myModule.value('appName', 'MyCoolApp'); |
|
| 155 | * |
|
| 156 | * // configure existing services inside initialization blocks. |
|
| 157 | * myModule.config(['$locationProvider', function($locationProvider) { |
|
| 158 | * // Configure existing providers |
|
| 159 | * $locationProvider.hashPrefix('!'); |
|
| 160 | * }]); |
|
| 161 | * ``` |
|
| 162 | * |
|
| 163 | * Then you can create an injector and load your modules like this: |
|
| 164 | * |
|
| 165 | * ```js |
|
| 166 | * var injector = angular.injector(['ng', 'myModule']) |
|
| 167 | * ``` |
|
| 168 | * |
|
| 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. |
|
| 172 | * |
|
| 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. |
|
| 179 | */ |
|
| 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); |
|
| 184 | } |
|
| 185 | }; |
|
| 186 | ||
| 187 | assertNotHasOwnProperty(name, 'module'); |
|
| 188 | if (requires && modules.hasOwnProperty(name)) { |
|
| 189 | modules[name] = null; |
|
| 190 | } |
|
| 191 | return ensure(modules, name, function() { |
|
| 192 | if (!requires) { |
|
| 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); |
|
| 196 | } |
|
| 197 | ||
| 198 | /** @type {!Array.<Array.<*>>} */ |
|
| 199 | var invokeQueue = []; |
|
| 200 | ||
| 201 | /** @type {!Array.<Function>} */ |
|
| 202 | var configBlocks = []; |
|
| 203 | ||
| 204 | /** @type {!Array.<Function>} */ |
|
| 205 | var runBlocks = []; |
|
| 206 | ||
| 207 | var config = invokeLater('$injector', 'invoke', 'push', configBlocks); |
|
| 208 | ||
| 209 | /** @type {angular.Module} */ |
|
| 210 | var moduleInstance = { |
|
| 211 | // Private state |
|
| 212 | _invokeQueue: invokeQueue, |
|
| 213 | _configBlocks: configBlocks, |
|
| 214 | _runBlocks: runBlocks, |
|
| 215 | ||
| 216 | /** |
|
| 217 | * @ngdoc property |
|
| 218 | * @name angular.Module#requires |
|
| 219 | * @module ng |
|
| 220 | * |
|
| 221 | * @description |
|
| 222 | * Holds the list of modules which the injector will load before the current module is |
|
| 223 | * loaded. |
|
| 224 | */ |
|
| 225 | requires: requires, |
|
| 226 | ||
| 227 | /** |
|
| 228 | * @ngdoc property |
|
| 229 | * @name angular.Module#name |
|
| 230 | * @module ng |
|
| 231 | * |
|
| 232 | * @description |
|
| 233 | * Name of the module. |
|
| 234 | */ |
|
| 235 | name: name, |
|
| 236 | ||
| 237 | ||
| 238 | /** |
|
| 239 | * @ngdoc method |
|
| 240 | * @name angular.Module#provider |
|
| 241 | * @module ng |
|
| 242 | * @param {string} name service name |
|
| 243 | * @param {Function} providerType Construction function for creating new instance of the |
|
| 244 | * service. |
|
| 245 | * @description |
|
| 246 | * See {@link auto.$provide#provider $provide.provider()}. |
|
| 247 | */ |
|
| 248 | provider: invokeLaterAndSetModuleName('$provide', 'provider'), |
|
| 249 | ||
| 250 | /** |
|
| 251 | * @ngdoc method |
|
| 252 | * @name angular.Module#factory |
|
| 253 | * @module ng |
|
| 254 | * @param {string} name service name |
|
| 255 | * @param {Function} providerFunction Function for creating new instance of the service. |
|
| 256 | * @description |
|
| 257 | * See {@link auto.$provide#factory $provide.factory()}. |
|
| 258 | */ |
|
| 259 | factory: invokeLaterAndSetModuleName('$provide', 'factory'), |
|
| 260 | ||
| 261 | /** |
|
| 262 | * @ngdoc method |
|
| 263 | * @name angular.Module#service |
|
| 264 | * @module ng |
|
| 265 | * @param {string} name service name |
|
| 266 | * @param {Function} constructor A constructor function that will be instantiated. |
|
| 267 | * @description |
|
| 268 | * See {@link auto.$provide#service $provide.service()}. |
|
| 269 | */ |
|
| 270 | service: invokeLaterAndSetModuleName('$provide', 'service'), |
|
| 271 | ||
| 272 | /** |
|
| 273 | * @ngdoc method |
|
| 274 | * @name angular.Module#value |
|
| 275 | * @module ng |
|
| 276 | * @param {string} name service name |
|
| 277 | * @param {*} object Service instance object. |
|
| 278 | * @description |
|
| 279 | * See {@link auto.$provide#value $provide.value()}. |
|
| 280 | */ |
|
| 281 | value: invokeLater('$provide', 'value'), |
|
| 282 | ||
| 283 | /** |
|
| 284 | * @ngdoc method |
|
| 285 | * @name angular.Module#constant |
|
| 286 | * @module ng |
|
| 287 | * @param {string} name constant name |
|
| 288 | * @param {*} object Constant value. |
|
| 289 | * @description |
|
| 290 | * Because the constants are fixed, they get applied before other provide methods. |
|
| 291 | * See {@link auto.$provide#constant $provide.constant()}. |
|
| 292 | */ |
|
| 293 | constant: invokeLater('$provide', 'constant', 'unshift'), |
|
| 294 | ||
| 295 | /** |
|
| 296 | * @ngdoc method |
|
| 297 | * @name angular.Module#decorator |
|
| 298 | * @module ng |
|
| 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. |
|
| 302 | * @description |
|
| 303 | * See {@link auto.$provide#decorator $provide.decorator()}. |
|
| 304 | */ |
|
| 305 | decorator: invokeLaterAndSetModuleName('$provide', 'decorator'), |
|
| 306 | ||
| 307 | /** |
|
| 308 | * @ngdoc method |
|
| 309 | * @name angular.Module#animation |
|
| 310 | * @module ng |
|
| 311 | * @param {string} name animation name |
|
| 312 | * @param {Function} animationFactory Factory function for creating new instance of an |
|
| 313 | * animation. |
|
| 314 | * @description |
|
| 315 | * |
|
| 316 | * **NOTE**: animations take effect only if the **ngAnimate** module is loaded. |
|
| 317 | * |
|
| 318 | * |
|
| 319 | * Defines an animation hook that can be later used with |
|
| 320 | * {@link $animate $animate} service and directives that use this service. |
|
| 321 | * |
|
| 322 | * ```js |
|
| 323 | * module.animation('.animation-name', function($inject1, $inject2) { |
|
| 324 | * return { |
|
| 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 |
|
| 330 | * } |
|
| 331 | * } |
|
| 332 | * } |
|
| 333 | * }) |
|
| 334 | * ``` |
|
| 335 | * |
|
| 336 | * See {@link ng.$animateProvider#register $animateProvider.register()} and |
|
| 337 | * {@link ngAnimate ngAnimate module} for more information. |
|
| 338 | */ |
|
| 339 | animation: invokeLaterAndSetModuleName('$animateProvider', 'register'), |
|
| 340 | ||
| 341 | /** |
|
| 342 | * @ngdoc method |
|
| 343 | * @name angular.Module#filter |
|
| 344 | * @module ng |
|
| 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. |
|
| 347 | * @description |
|
| 348 | * See {@link ng.$filterProvider#register $filterProvider.register()}. |
|
| 349 | * |
|
| 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`). |
|
| 355 | * </div> |
|
| 356 | */ |
|
| 357 | filter: invokeLaterAndSetModuleName('$filterProvider', 'register'), |
|
| 358 | ||
| 359 | /** |
|
| 360 | * @ngdoc method |
|
| 361 | * @name angular.Module#controller |
|
| 362 | * @module ng |
|
| 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. |
|
| 366 | * @description |
|
| 367 | * See {@link ng.$controllerProvider#register $controllerProvider.register()}. |
|
| 368 | */ |
|
| 369 | controller: invokeLaterAndSetModuleName('$controllerProvider', 'register'), |
|
| 370 | ||
| 371 | /** |
|
| 372 | * @ngdoc method |
|
| 373 | * @name angular.Module#directive |
|
| 374 | * @module ng |
|
| 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 |
|
| 378 | * directives. |
|
| 379 | * @description |
|
| 380 | * See {@link ng.$compileProvider#directive $compileProvider.directive()}. |
|
| 381 | */ |
|
| 382 | directive: invokeLaterAndSetModuleName('$compileProvider', 'directive'), |
|
| 383 | ||
| 384 | /** |
|
| 385 | * @ngdoc method |
|
| 386 | * @name angular.Module#component |
|
| 387 | * @module ng |
|
| 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}) |
|
| 391 | * |
|
| 392 | * @description |
|
| 393 | * See {@link ng.$compileProvider#component $compileProvider.component()}. |
|
| 394 | */ |
|
| 395 | component: invokeLaterAndSetModuleName('$compileProvider', 'component'), |
|
| 396 | ||
| 397 | /** |
|
| 398 | * @ngdoc method |
|
| 399 | * @name angular.Module#config |
|
| 400 | * @module ng |
|
| 401 | * @param {Function} configFn Execute this function on module load. Useful for service |
|
| 402 | * configuration. |
|
| 403 | * @description |
|
| 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}. |
|
| 407 | */ |
|
| 408 | config: config, |
|
| 409 | ||
| 410 | /** |
|
| 411 | * @ngdoc method |
|
| 412 | * @name angular.Module#run |
|
| 413 | * @module ng |
|
| 414 | * @param {Function} initializationFn Execute this function after injector creation. |
|
| 415 | * Useful for application initialization. |
|
| 416 | * @description |
|
| 417 | * Use this method to register work which should be performed when the injector is done |
|
| 418 | * loading all modules. |
|
| 419 | */ |
|
| 420 | run: function(block) { |
|
| 421 | runBlocks.push(block); |
|
| 422 | return this; |
|
| 423 | } |
|
| 424 | }; |
|
| 425 | ||
| 426 | if (configFn) { |
|
| 427 | config(configFn); |
|
| 428 | } |
|
| 429 | ||
| 430 | return moduleInstance; |
|
| 431 | ||
| 432 | /** |
|
| 433 | * @param {string} provider |
|
| 434 | * @param {string} method |
|
| 435 | * @param {String=} insertMethod |
|
| 436 | * @returns {angular.Module} |
|
| 437 | */ |
|
| 438 | function invokeLater(provider, method, insertMethod, queue) { |
|
| 439 | if (!queue) queue = invokeQueue; |
|
| 440 | return function() { |
|
| 441 | queue[insertMethod || 'push']([provider, method, arguments]); |
|
| 442 | return moduleInstance; |
|
| 443 | }; |
|
| 444 | } |
|
| 445 | ||
| 446 | /** |
|
| 447 | * @param {string} provider |
|
| 448 | * @param {string} method |
|
| 449 | * @returns {angular.Module} |
|
| 450 | */ |
|
| 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; |
|
| 456 | }; |
|
| 457 | } |
|
| 458 | }); |
|
| 459 | }; |
|
| 460 | }); |
|
| 461 | ||
| 462 | } |
|
| 463 | ||
| 464 | setupModuleLoader(window); |
|
| 465 | })(window); |
|