mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-22 10:49:24 +08:00
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user