7
7
This page explains the Angular initialization process and how you can manually initialize Angular
8
8
if necessary.
9
9
10
-
11
- # Angular `<script>` Tag
10
+ ## Angular `<script>` Tag
12
11
13
12
This example shows the recommended path for integrating Angular with what we call automatic
14
13
initialization.
@@ -50,7 +49,7 @@ initialization.
50
49
51
50
52
51
53
- # Automatic Initialization
52
+ ## Automatic Initialization
54
53
55
54
Angular initializes automatically upon `DOMContentLoaded` event or when the `angular.js` script is
56
55
evaluated if at that time `document.readyState` is set to `'complete'`. At this point Angular looks
@@ -76,16 +75,14 @@ If the {@link api/ng.directive:ngApp `ng-app`} directive is found then Angular w
76
75
77
76
78
77
79
- # Manual Initialization
78
+ ## Manual Initialization
80
79
81
80
82
81
If you need to have more control over the initialization process, you can use a manual
83
82
bootstrapping method instead. Examples of when you'd need to do this include using script loaders
84
83
or the need to perform an operation before Angular compiles a page.
85
84
86
-
87
- Here is an example of manually initializing Angular. The example is equivalent to using the {@link
88
- api/ng.directive:ngApp ng-app} directive.
85
+ Here is an example of manually initializing Angular:
89
86
90
87
<pre>
91
88
<!doctype html>
@@ -95,17 +92,22 @@ api/ng.directive:ngApp ng-app} directive.
95
92
<script src="http://code.angularjs.org/angular.js"></script>
96
93
<script>
97
94
angular.element(document).ready(function() {
98
- angular.bootstrap(document);
95
+ angular.bootstrap(document, ['optionalModuleName'] );
99
96
});
100
97
</script>
101
98
</body>
102
99
</html>
103
100
</pre>
104
101
102
+ Note that we have provided the name of our application module to be loaded into the injector as the second
103
+ parameter of the {@link api/angular.bootstrap} function. This example is equivalent to using the
104
+ {@link api/ng.directive:ngApp ng-app} directive, with `ng-app="optionalModuleName"`, as in the automatic
105
+ initialization example above.
106
+
105
107
This is the sequence that your code should follow:
106
108
107
- 1. After the page and all of the code is loaded, find the root of the HTML template, which is
108
- typically the root of the document.
109
+ 1. After the page and all of the code is loaded, find the root element of your AngularJS
110
+ application, which is typically the root of the document.
109
111
110
- 2. Call {@link api/angular.bootstrap} to {@link compiler compile} the template into an
112
+ 2. Call {@link api/angular.bootstrap} to {@link compiler compile} the element into an
111
113
executable, bi-directionally bound application.
0 commit comments