From 186a840cd34d3ffed7b351a1827e7736cd8d54c3 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 10 Nov 2011 20:04:15 -0800 Subject: feat(bootstrap): added angular.bootstrap method --- src/Angular.js | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'src/Angular.js') diff --git a/src/Angular.js b/src/Angular.js index 66b592f2..096f5b53 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -819,29 +819,44 @@ function encodeUriQuery(val, pctEncodeSpaces) { * `ng:autobind="[root element ID]"` tells Angular to compile and manage part of the document, * starting at "root element ID". * - */ function angularInit(config, document){ var autobind = config.autobind; if (autobind) { - var modules = [ngModule]; + var modules = []; forEach((config.modules || '').split(','), function(module){ module = trim(module); if (module) { modules.push(module); } }); - createInjector(modules, angularModule)(['$rootScope', '$compile', '$injector', function(scope, compile, injector){ - scope.$apply(function(){ - var element = jqLite(isString(autobind) ? document.getElementById(autobind) : document); - element.data('$injector', injector); - compile(element)(scope); - }); - }]); + bootstrap(jqLite(isString(autobind) ? document.getElementById(autobind) : document), modules); } } +/** + * @ngdoc function + * @name angular.bootstrap + * @description + * Use this function to manually start up angular application. + * + * See: {@link guide/dev_guide.bootstrap.manual_bootstrap Bootstrap} + * + * @param {Element} element DOM element which is the root of angular application. + * @param {Array=} modules an array of module declarations. See: {@link angular.module modules} + */ +function bootstrap(element, modules) { + modules = modules || []; + modules.unshift(ngModule); + createInjector(modules, angularModule)(['$rootScope', '$compile', '$injector', function(scope, compile, injector){ + scope.$apply(function() { + element.data('$injector', injector); + compile(element)(scope); + }); + }]); +} + function angularJsConfig(document) { bindJQuery(); var scripts = document.getElementsByTagName('script'), @@ -903,6 +918,7 @@ function assertArgFn(arg, name) { function publishExternalAPI(angular){ extend(angular, { + 'bootstrap': bootstrap, 'copy': copy, 'extend': extend, 'equals': equals, -- cgit v1.2.3