22@name Developer Guide: Initializing Angular: Manual Initialization
33@description
44
5- Letting angular handle the initialization process (bootstrapping) is a handy way to start using
6- angular, but advanced users who want more control over the initialization process can choose to use
7- the manual bootstrapping method instead .
5+ In the vast majority of cases you'll want to let Angular handle initialization automatically.
6+ If, however, you need to delay Angular from managing the page right after the DOMContentLoaded
7+ event fires, you'll need to control this initialization manually .
88
9- The best way to get started with manual bootstrapping is to look at the what happens when you use
10- {@link api/angular.module.ng.$compileProvider.directive.ng-app ng-app}, by showing each step of the process
11- explicitly.
9+ To initialize Angular -- after you've done your own special-purpose initialization -- just call
10+ the {@link api/angular.bootstrap bootstrap()} function with the HTML container node that you want
11+ Angular to manage. In automatic initialization you'd do this by adding the `ng-app` attribute to
12+ the same node. Now, you won't use `ng-app` anywhere in your document.
13+
14+ To show the contrast of manual vs. automatic initialization, this automatic method:
15+
16+ <pre>
17+ <!doctype html>
18+ <html ng-app>
19+ <head>
20+ <script src="http://code.angularjs.org/angular.js"></script>
21+ ...
22+ </pre
23+
24+ is the same as this manual method:
1225
1326<pre>
1427<!doctype html>
@@ -21,19 +34,9 @@ explicitly.
2134 });
2235 </script>
2336</head>
24- <body>
25- Hello {{'World'}}!
26- </body>
27- </html>
37+ ...
2838</pre>
2939
30- This is the sequence that your code should follow if you bootstrap angular on your own:
31-
32- 1. After the page is loaded, find the root of the HTML template, which is typically the root of
33- the document.
34- 2. Call {@link api/angular.bootstrap} to {@link dev_guide.compiler compile} the template into
35- an executable, bi-directionally bound application.
36-
3740
3841## Related Topics
3942
0 commit comments