X Tutup
Skip to content

Commit 2ce0485

Browse files
committed
Rewrite of Automatic Initialization doc
Added examples, explained the reasons why you initialize the whole app or parts of the page.
1 parent a08cbc0 commit 2ce0485

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

docs/content/guide/dev_guide.bootstrap.auto_bootstrap.ngdoc

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
@name Developer Guide: Initializing Angular: Automatic Initialization
33
@description
44

5-
Angular initializes automatically when you load the angular script into your page that contains an element
6-
with `ng-app` directive:
5+
For Angular to manage the DOM for your application, it needs to compile some or all of an HTML page. Angular does this initialization automatically when you load the angular.js script into your page and insert an `ng-app` directive (attribute) into one of the page's elements. For example, we can tell Angular to initialize the entire document:
76

87
<pre>
98
<!doctype html>
@@ -17,30 +16,36 @@ with `ng-app` directive:
1716
</html>
1817
</pre>
1918

20-
From a high-level view, this is what happens during angular's automatic initialization process:
19+
You can also tell Angular to manage only a portion of a page. You would want to do this if you are using some other framework to manage other parts of the page. You do this by placing the `ng-app` directive on one or more container elements in the document. For example:
2120

22-
1. The browser loads the page, and then runs the angular script. Angular waits for the
23-
`DOMContentLoaded` (or 'Load') event to attempt to bootstrap.
21+
<pre>
22+
<div ng-app>
23+
I can add: {{ 1+2 }}
24+
</div>
25+
</pre>
2426

25-
2. Angular looks for the `ng-app` directive. If found it then proceeds to compile the DOM element and its children.
26-
Optionally the `ng-app` may specify a {@link api/angular.module module} to load before the compilation. For details on
27-
how the compiler works, see {@link dev_guide.compiler Angular HTML Compiler}.
27+
You can also ask `ng-app` to load additional {@link api/angular.module modules} containing services, directives or filers that you'll use on the page.
28+
29+
<pre>
30+
<div ng-app="AwesomeModule">
31+
...
32+
</div>
33+
</pre
2834

2935

30-
## Initialization Options
36+
From a high-level, here's what Angular does during the initialization process:
3137

32-
The reason why `ng-app` exists is because angular should not assume that the entire HTML
33-
document should be processed just because the `angular.js` script is included. In order to compile
34-
only a part of the document set the `ng-app` on the root element of this portion.
38+
1. The browser loads the page, and then runs the Angular script. Angular then waits for the
39+
`DOMContentLoaded` (or 'Load') event to attempt to initialize.
3540

36-
## Global Angular Object
41+
2. Angular looks for the `ng-app` directive. If found it compilies the DOM element containing `ng-app` and its children.
3742

38-
The angular script creates a single global variable `angular` in the global namespace. All angular
39-
APIs are bound to fields of this global object.
43+
3. Angular creates a global variable `angular` and binds all Angular APIs to this object's fields.
4044

4145

4246
## Related Topics
4347

48+
* {@link dev_guide.compiler Angular HTML Compiler}
4449
* {@link dev_guide.bootstrap Initializing Angular}
4550
* {@link dev_guide.bootstrap.manual_bootstrap Manual Initialization}
4651

0 commit comments

Comments
 (0)
X Tutup