|
1 |
| -@ngdoc overview |
2 |
| -@name Developer Guide: Bootstrap |
3 |
| -@description |
4 |
| - |
5 |
| -# Overview |
6 |
| - |
7 |
| -This page explains the Angular initialization process and how you can manually initialize Angular |
8 |
| -if necessary. |
9 |
| - |
10 |
| - |
11 |
| -# Angular `<script>` Tag |
12 |
| - |
13 |
| -This example shows the recommended path for integrating Angular with what we call automatic |
14 |
| -initialization. |
15 |
| - |
16 |
| - |
17 |
| -<pre> |
18 |
| -<!doctype html> |
19 |
| -<html xmlns:ng="http://angularjs.org" ng-app> |
20 |
| - <body> |
21 |
| - ... |
22 |
| - <script src="angular.js"> |
23 |
| - </body> |
24 |
| -</html> |
25 |
| -</pre> |
26 |
| - |
27 |
| - * Place the `script` tag at the buttom of the page. Placing script tags at the end of the page |
28 |
| - improves app load time becouse the HTML loading is not blocked by loading of the `angular.js` |
29 |
| - script. You can get the latest bits from {@link http://code.angularjs.org}. Please don't link |
30 |
| - your production code to this URL, as it will expose a security hole on your site. For |
31 |
| - experimental development linking to our site is fine. |
32 |
| - * Choose: `angular-[version].js` for a human-readable file, suitable for development and |
33 |
| - debugging. |
34 |
| - * Choose: `angular-[version].min.js` for a compressed and obfuscated file, suitable for use in |
35 |
| - production. |
36 |
| - * Place `ng-app` to the root of your application, typically on the `<html>` tag if you want |
37 |
| - anugular to auto-bootstrap your application. |
38 |
| - |
39 |
| - <html ng-app> |
40 |
| - |
41 |
| - * If you choose to use the old style directive syntax `ng:` then include xml-namespace in `html` |
42 |
| - to make IE happy. (This is here for historical resons, and we no longer recomend use of |
43 |
| - `ng:`.) |
44 |
| - |
45 |
| - <html xmlns:ng="http://angularjs.org"> |
46 |
| - |
47 |
| - |
48 |
| - |
49 |
| -# Automatic Initialization |
50 |
| - |
51 |
| -Angular initializes automatically upon `DOMContentLoaded` event, at which point Angular looks for |
52 |
| -the {@link api/ng.directive:ngApp `ng-app`} directive which |
53 |
| -designates your application root. If the {@link |
54 |
| -api/ng.directive:ngApp `ng-app`} directive is found then Angular |
55 |
| -will: |
56 |
| - |
57 |
| - * load the {@link guide/module module} associated with the directive. |
58 |
| - * create the application {@link api/AUTO.$injector injector} |
59 |
| - * compile the DOM treating the {@link api/ng.directive:ngApp |
60 |
| - `ng-app`} directive as the root of the compilation. This allows you to tell it to treat only a |
61 |
| - portion of the DOM as an Angular application. |
62 |
| - |
63 |
| - |
64 |
| -<pre> |
65 |
| -<!doctype html> |
66 |
| -<html ng-app="optionalModuleName"> |
67 |
| - <body> |
68 |
| - I can add: {{ 1+2 }}. |
69 |
| - <script src="angular.js"></script> |
70 |
| - </body> |
71 |
| -</html> |
72 |
| -</pre> |
73 |
| - |
74 |
| - |
75 |
| - |
76 |
| -# Manual Initialization |
77 |
| - |
78 |
| - |
79 |
| -If you need to have more control over the initialization process, you can use a manual |
80 |
| -bootstrapping method instead. Examples of when you'd need to do this include using script loaders |
81 |
| -or the need to perform an operation before Angular compiles a page. |
82 |
| - |
83 |
| - |
84 |
| -Here is an example of manually initializing Angular. The example is equivalent to using the {@link |
85 |
| -api/ng.directive:ngApp ng-app} directive. |
86 |
| - |
87 |
| -<pre> |
88 |
| -<!doctype html> |
89 |
| -<html xmlns:ng="http://angularjs.org"> |
90 |
| - <body> |
91 |
| - Hello {{'World'}}! |
92 |
| - <script src="http://code.angularjs.org/angular.js"></script> |
93 |
| - <script> |
94 |
| - angular.element(document).ready(function() { |
95 |
| - angular.bootstrap(document); |
96 |
| - }); |
97 |
| - </script> |
98 |
| - </body> |
99 |
| -</html> |
100 |
| -</pre> |
101 |
| - |
102 |
| -This is the sequence that your code should follow: |
103 |
| - |
104 |
| - 1. After the page and all of the code is loaded, find the root of the HTML template, which is |
105 |
| - typically the root of the document. |
106 |
| - |
107 |
| - 2. Call {@link api/angular.bootstrap} to {@link compiler compile} the template into an |
108 |
| - executable, bi-directionally bound application. |
| 1 | +@ngdoc overview |
| 2 | +@name Developer Guide: Bootstrap |
| 3 | +@description |
| 4 | +
|
| 5 | +# Overview |
| 6 | +
|
| 7 | +This page explains the Angular initialization process and how you can manually initialize Angular |
| 8 | +if necessary. |
| 9 | +
|
| 10 | +
|
| 11 | +# Angular `<script>` Tag |
| 12 | +
|
| 13 | +This example shows the recommended path for integrating Angular with what we call automatic |
| 14 | +initialization. |
| 15 | +
|
| 16 | +
|
| 17 | +<pre> |
| 18 | +<!doctype html> |
| 19 | +<html xmlns:ng="http://angularjs.org" ng-app> |
| 20 | + <body> |
| 21 | + ... |
| 22 | + <script src="angular.js"> |
| 23 | + </body> |
| 24 | +</html> |
| 25 | +</pre> |
| 26 | +
|
| 27 | + * Place the `script` tag at the buttom of the page. Placing script tags at the end of the page |
| 28 | + improves app load time because the HTML loading is not blocked by loading of the `angular.js` |
| 29 | + script. You can get the latest bits from {@link http://code.angularjs.org}. Please don't link |
| 30 | + your production code to this URL, as it will expose a security hole on your site. For |
| 31 | + experimental development linking to our site is fine. |
| 32 | + * Choose: `angular-[version].js` for a human-readable file, suitable for development and |
| 33 | + debugging. |
| 34 | + * Choose: `angular-[version].min.js` for a compressed and obfuscated file, suitable for use in |
| 35 | + production. |
| 36 | + * Place `ng-app` to the root of your application, typically on the `<html>` tag if you want |
| 37 | + anugular to auto-bootstrap your application. |
| 38 | +
|
| 39 | + <html ng-app> |
| 40 | +
|
| 41 | + * If you choose to use the old style directive syntax `ng:` then include xml-namespace in `html` |
| 42 | + to make IE happy. (This is here for historical resons, and we no longer recomend use of |
| 43 | + `ng:`.) |
| 44 | +
|
| 45 | + <html xmlns:ng="http://angularjs.org"> |
| 46 | +
|
| 47 | +
|
| 48 | +
|
| 49 | +# Automatic Initialization |
| 50 | +
|
| 51 | +Angular initializes automatically upon `DOMContentLoaded` event, at which point Angular looks for |
| 52 | +the {@link api/ng.directive:ngApp `ng-app`} directive which |
| 53 | +designates your application root. If the {@link |
| 54 | +api/ng.directive:ngApp `ng-app`} directive is found then Angular |
| 55 | +will: |
| 56 | +
|
| 57 | + * load the {@link guide/module module} associated with the directive. |
| 58 | + * create the application {@link api/AUTO.$injector injector} |
| 59 | + * compile the DOM treating the {@link api/ng.directive:ngApp |
| 60 | + `ng-app`} directive as the root of the compilation. This allows you to tell it to treat only a |
| 61 | + portion of the DOM as an Angular application. |
| 62 | +
|
| 63 | +
|
| 64 | +<pre> |
| 65 | +<!doctype html> |
| 66 | +<html ng-app="optionalModuleName"> |
| 67 | + <body> |
| 68 | + I can add: {{ 1+2 }}. |
| 69 | + <script src="angular.js"></script> |
| 70 | + </body> |
| 71 | +</html> |
| 72 | +</pre> |
| 73 | +
|
| 74 | +
|
| 75 | +
|
| 76 | +# Manual Initialization |
| 77 | +
|
| 78 | +
|
| 79 | +If you need to have more control over the initialization process, you can use a manual |
| 80 | +bootstrapping method instead. Examples of when you'd need to do this include using script loaders |
| 81 | +or the need to perform an operation before Angular compiles a page. |
| 82 | +
|
| 83 | +
|
| 84 | +Here is an example of manually initializing Angular. The example is equivalent to using the {@link |
| 85 | +api/ng.directive:ngApp ng-app} directive. |
| 86 | +
|
| 87 | +<pre> |
| 88 | +<!doctype html> |
| 89 | +<html xmlns:ng="http://angularjs.org"> |
| 90 | + <body> |
| 91 | + Hello {{'World'}}! |
| 92 | + <script src="http://code.angularjs.org/angular.js"></script> |
| 93 | + <script> |
| 94 | + angular.element(document).ready(function() { |
| 95 | + angular.bootstrap(document); |
| 96 | + }); |
| 97 | + </script> |
| 98 | + </body> |
| 99 | +</html> |
| 100 | +</pre> |
| 101 | +
|
| 102 | +This is the sequence that your code should follow: |
| 103 | +
|
| 104 | + 1. After the page and all of the code is loaded, find the root of the HTML template, which is |
| 105 | + typically the root of the document. |
| 106 | +
|
| 107 | + 2. Call {@link api/angular.bootstrap} to {@link compiler compile} the template into an |
| 108 | + executable, bi-directionally bound application. |
0 commit comments