feat(JQLite): ready() now supports document.readyState=='complete'

JQLite.ready() used for automatic bootstrapping (when jQuery is not present)
now checks if document already is ready when first called. This simplifies
bootstrapping when the angular script is loaded asynchronously.

However if other scripts with angular app code are being loaded as well
it is developers responsibility to ensure that these scripts are loaded
after angular-loader.js is evaluated and before angular.js script is
evaluated.
This commit is contained in:
Jørgen Borgesen 2013-02-06 12:15:18 +01:00 committed by Igor Minar
parent 6a612df7de
commit 753fc9e58d
2 changed files with 12 additions and 8 deletions

View file

@ -48,11 +48,10 @@ initialization.
# Automatic Initialization # Automatic Initialization
Angular initializes automatically upon `DOMContentLoaded` event, at which point Angular looks for Angular initializes automatically upon `DOMContentLoaded` event or when the `angular.js` script is
the {@link api/ng.directive:ngApp `ng-app`} directive which evaluated if at that time `document.readyState` is set to `'complete'`. At this point Angular looks
designates your application root. If the {@link for the {@link api/ng.directive:ngApp `ng-app`} directive which designates your application root.
api/ng.directive:ngApp `ng-app`} directive is found then Angular If the {@link api/ng.directive:ngApp `ng-app`} directive is found then Angular will:
will:
* load the {@link guide/module module} associated with the directive. * load the {@link guide/module module} associated with the directive.
* create the application {@link api/AUTO.$injector injector} * create the application {@link api/AUTO.$injector injector}

View file

@ -327,9 +327,14 @@ var JQLitePrototype = JQLite.prototype = {
fn(); fn();
} }
this.bind('DOMContentLoaded', trigger); // works for modern browsers and IE9 // check if document already is loaded
// we can not use jqLite since we are not done loading and jQuery could be loaded later. if (document.readyState === 'complete'){
JQLite(window).bind('load', trigger); // fallback to window.onload for others setTimeout(trigger);
} else {
this.bind('DOMContentLoaded', trigger); // works for modern browsers and IE9
// we can not use jqLite since we are not done loading and jQuery could be loaded later.
JQLite(window).bind('load', trigger); // fallback to window.onload for others
}
}, },
toString: function() { toString: function() {
var value = []; var value = [];