diff options
| author | Julie | 2013-02-21 11:55:16 -0800 |
|---|---|---|
| committer | Igor Minar | 2013-03-06 16:19:35 -0800 |
| commit | 603fe0d19608ffe1915d8bc23bf412912e7ee1ac (patch) | |
| tree | a234c62b845bfe614d1b3794fc0a693a8455712f /src/Angular.js | |
| parent | 485f1040990508441cebf4cddab83a126e65355f (diff) | |
| download | angular.js-603fe0d19608ffe1915d8bc23bf412912e7ee1ac.tar.bz2 | |
feat(angular.bootstrap): support deferred bootstrap
This features enables tools like Batarang and test runners to
hook into angular's bootstrap process and sneak in more modules
into the DI registry which can replace or augment DI services for
the purpose of instrumentation or mocking out heavy dependencies.
If window.name contains prefix NG_DEFER_BOOTSTRAP! when
angular.bootstrap is called, the bootstrap process will be paused
until angular.resumeBootstrap is called.
angular.resumeBootstrap takes an optional array of modules that
should be added to the original list of modules that the app was
about to be bootstrapped with.
Diffstat (limited to 'src/Angular.js')
| -rw-r--r-- | src/Angular.js | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/src/Angular.js b/src/Angular.js index 5de57075..5d9d2e12 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -58,7 +58,7 @@ var /** holds major version number for IE or NaN for real browsers */ toString = Object.prototype.toString, - _angular = window.angular, + _angular = window.angular, /** @name angular */ angular = window.angular || (window.angular = {}), angularModule, @@ -964,22 +964,38 @@ function angularInit(element, bootstrap) { * @returns {AUTO.$injector} Returns the newly created injector for this app. */ function bootstrap(element, modules) { - element = jqLite(element); - modules = modules || []; - modules.unshift(['$provide', function($provide) { - $provide.value('$rootElement', element); - }]); - modules.unshift('ng'); - var injector = createInjector(modules); - injector.invoke( - ['$rootScope', '$rootElement', '$compile', '$injector', function(scope, element, compile, injector){ - scope.$apply(function() { - element.data('$injector', injector); - compile(element)(scope); - }); - }] - ); - return injector; + var resumeBootstrapInternal = function() { + element = jqLite(element); + modules = modules || []; + modules.unshift(['$provide', function($provide) { + $provide.value('$rootElement', element); + }]); + modules.unshift('ng'); + var injector = createInjector(modules); + injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector', + function(scope, element, compile, injector) { + scope.$apply(function() { + element.data('$injector', injector); + compile(element)(scope); + }); + }] + ); + return injector; + }; + + var NG_DEFER_BOOTSTRAP = /^NG_DEFER_BOOTSTRAP!/; + + if (window && !NG_DEFER_BOOTSTRAP.test(window.name)) { + return resumeBootstrapInternal(); + } + + window.name = window.name.replace(NG_DEFER_BOOTSTRAP, ''); + angular.resumeBootstrap = function(extraModules) { + forEach(extraModules, function(module) { + modules.push(module); + }); + resumeBootstrapInternal(); + }; } var SNAKE_CASE_REGEXP = /[A-Z]/g; |
