Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 753fc9e

Browse files
jorgenfbIgorMinar
authored andcommitted
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.
1 parent 6a612df commit 753fc9e

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

docs/content/guide/bootstrap.ngdoc

+4-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ initialization.
4848

4949
# Automatic Initialization
5050

51-
Angular initializes automatically upon `DOMContentLoaded` event, at which point Angular looks for
52-
the {@link api/ng.directive:ngApp `ng-app`} directive which
53-
designates your application root. If the {@link
54-
api/ng.directive:ngApp `ng-app`} directive is found then Angular
55-
will:
51+
Angular initializes automatically upon `DOMContentLoaded` event or when the `angular.js` script is
52+
evaluated if at that time `document.readyState` is set to `'complete'`. At this point Angular looks
53+
for the {@link api/ng.directive:ngApp `ng-app`} directive which designates your application root.
54+
If the {@link api/ng.directive:ngApp `ng-app`} directive is found then Angular will:
5655

5756
* load the {@link guide/module module} associated with the directive.
5857
* create the application {@link api/AUTO.$injector injector}

src/jqLite.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,14 @@ var JQLitePrototype = JQLite.prototype = {
327327
fn();
328328
}
329329

330-
this.bind('DOMContentLoaded', trigger); // works for modern browsers and IE9
331-
// we can not use jqLite since we are not done loading and jQuery could be loaded later.
332-
JQLite(window).bind('load', trigger); // fallback to window.onload for others
330+
// check if document already is loaded
331+
if (document.readyState === 'complete'){
332+
setTimeout(trigger);
333+
} else {
334+
this.bind('DOMContentLoaded', trigger); // works for modern browsers and IE9
335+
// we can not use jqLite since we are not done loading and jQuery could be loaded later.
336+
JQLite(window).bind('load', trigger); // fallback to window.onload for others
337+
}
333338
},
334339
toString: function() {
335340
var value = [];

0 commit comments

Comments
 (0)