mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-17 03:01:06 +00:00
docs(guide/bootstrap): clarify manual bootstrapping
This commit is contained in:
parent
1fac36e2cb
commit
7eb15c46a2
1 changed files with 13 additions and 11 deletions
|
|
@ -7,8 +7,7 @@
|
||||||
This page explains the Angular initialization process and how you can manually initialize Angular
|
This page explains the Angular initialization process and how you can manually initialize Angular
|
||||||
if necessary.
|
if necessary.
|
||||||
|
|
||||||
|
## Angular `<script>` Tag
|
||||||
# Angular `<script>` Tag
|
|
||||||
|
|
||||||
This example shows the recommended path for integrating Angular with what we call automatic
|
This example shows the recommended path for integrating Angular with what we call automatic
|
||||||
initialization.
|
initialization.
|
||||||
|
|
@ -50,7 +49,7 @@ initialization.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Automatic Initialization
|
## Automatic Initialization
|
||||||
|
|
||||||
Angular initializes automatically upon `DOMContentLoaded` event, at which point Angular looks for
|
Angular initializes automatically upon `DOMContentLoaded` event, at which point Angular looks for
|
||||||
the {@link api/ng.directive:ngApp `ng-app`} directive which
|
the {@link api/ng.directive:ngApp `ng-app`} directive which
|
||||||
|
|
@ -77,16 +76,14 @@ will:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Manual Initialization
|
## Manual Initialization
|
||||||
|
|
||||||
|
|
||||||
If you need to have more control over the initialization process, you can use a manual
|
If you need to have more control over the initialization process, you can use a manual
|
||||||
bootstrapping method instead. Examples of when you'd need to do this include using script loaders
|
bootstrapping method instead. Examples of when you'd need to do this include using script loaders
|
||||||
or the need to perform an operation before Angular compiles a page.
|
or the need to perform an operation before Angular compiles a page.
|
||||||
|
|
||||||
|
Here is an example of manually initializing Angular:
|
||||||
Here is an example of manually initializing Angular. The example is equivalent to using the {@link
|
|
||||||
api/ng.directive:ngApp ng-app} directive.
|
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
|
|
@ -96,17 +93,22 @@ api/ng.directive:ngApp ng-app} directive.
|
||||||
<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.bootstrap(document);
|
angular.bootstrap(document, ['optionalModuleName']);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
Note that we have provided the name of our application module to be loaded into the injector as the second
|
||||||
|
parameter of the {@link api/angular.bootstrap} function. This example is equivalent to using the
|
||||||
|
{@link api/ng.directive:ngApp ng-app} directive, with `ng-app="optionalModuleName"`, as in the automatic
|
||||||
|
initialization example above.
|
||||||
|
|
||||||
This is the sequence that your code should follow:
|
This is the sequence that your code should follow:
|
||||||
|
|
||||||
1. After the page and all of the code is loaded, find the root of the HTML template, which is
|
1. After the page and all of the code is loaded, find the root element of your AngularJS
|
||||||
typically the root of the document.
|
application, which is typically the root of the document.
|
||||||
|
|
||||||
2. Call {@link api/angular.bootstrap} to {@link compiler compile} the template into an
|
2. Call {@link api/angular.bootstrap} to {@link compiler compile} the element into an
|
||||||
executable, bi-directionally bound application.
|
executable, bi-directionally bound application.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue