2
2
@name Developer Guide: Initializing Angular: Manual Initialization
3
3
@description
4
4
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 .
8
8
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:
12
25
13
26
<pre>
14
27
<!doctype html>
@@ -21,19 +34,9 @@ explicitly.
21
34
});
22
35
</script>
23
36
</head>
24
- <body>
25
- Hello {{'World'}}!
26
- </body>
27
- </html>
37
+ ...
28
38
</pre>
29
39
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
-
37
40
38
41
## Related Topics
39
42
0 commit comments