mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-12 00:43:10 +00:00
feat(bootstrap): added angular.bootstrap method
This commit is contained in:
parent
b09595a3c1
commit
186a840cd3
3 changed files with 37 additions and 10 deletions
|
|
@ -17,7 +17,7 @@ explicitly.
|
||||||
<script src="http://code.angularjs.org/angular.js"></script>
|
<script src="http://code.angularjs.org/angular.js"></script>
|
||||||
<script>
|
<script>
|
||||||
angular.element(document).ready(function() {
|
angular.element(document).ready(function() {
|
||||||
angular.compile(document)().$apply();
|
angular.bootstrap(document);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -819,29 +819,44 @@ function encodeUriQuery(val, pctEncodeSpaces) {
|
||||||
* `ng:autobind="[root element ID]"` tells Angular to compile and manage part of the document,
|
* `ng:autobind="[root element ID]"` tells Angular to compile and manage part of the document,
|
||||||
* starting at "root element ID".
|
* starting at "root element ID".
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
function angularInit(config, document){
|
function angularInit(config, document){
|
||||||
var autobind = config.autobind;
|
var autobind = config.autobind;
|
||||||
|
|
||||||
if (autobind) {
|
if (autobind) {
|
||||||
var modules = [ngModule];
|
var modules = [];
|
||||||
forEach((config.modules || '').split(','), function(module){
|
forEach((config.modules || '').split(','), function(module){
|
||||||
module = trim(module);
|
module = trim(module);
|
||||||
if (module) {
|
if (module) {
|
||||||
modules.push(module);
|
modules.push(module);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
createInjector(modules, angularModule)(['$rootScope', '$compile', '$injector', function(scope, compile, injector){
|
bootstrap(jqLite(isString(autobind) ? document.getElementById(autobind) : document), modules);
|
||||||
scope.$apply(function(){
|
|
||||||
var element = jqLite(isString(autobind) ? document.getElementById(autobind) : document);
|
|
||||||
element.data('$injector', injector);
|
|
||||||
compile(element)(scope);
|
|
||||||
});
|
|
||||||
}]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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<String,function>=} 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) {
|
function angularJsConfig(document) {
|
||||||
bindJQuery();
|
bindJQuery();
|
||||||
var scripts = document.getElementsByTagName('script'),
|
var scripts = document.getElementsByTagName('script'),
|
||||||
|
|
@ -903,6 +918,7 @@ function assertArgFn(arg, name) {
|
||||||
|
|
||||||
function publishExternalAPI(angular){
|
function publishExternalAPI(angular){
|
||||||
extend(angular, {
|
extend(angular, {
|
||||||
|
'bootstrap': bootstrap,
|
||||||
'copy': copy,
|
'copy': copy,
|
||||||
'extend': extend,
|
'extend': extend,
|
||||||
'equals': equals,
|
'equals': equals,
|
||||||
|
|
|
||||||
|
|
@ -529,4 +529,15 @@ describe('angular', function() {
|
||||||
expect(version.codeName).toBe('"NG_VERSION_CODENAME"');
|
expect(version.codeName).toBe('"NG_VERSION_CODENAME"');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('bootstrap', function() {
|
||||||
|
it('should bootstrap app', function(){
|
||||||
|
var element = jqLite('<div>{{1+2}}</div>');
|
||||||
|
var injector;
|
||||||
|
angular.bootstrap(element, [function($injector){ injector = $injector; }]);
|
||||||
|
expect(injector).toBeDefined();
|
||||||
|
expect(element.data('$injector')).toBe(injector);
|
||||||
|
dealoc(element);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue