forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarted.html
124 lines (95 loc) · 5.99 KB
/
started.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<h1>Getting Started</h1>
<div class="getting-started"><h2>Hello World!</h2>
<p>A great way for you to get started with AngularJS is to create the tradtional
"Hello World!" app:</p>
<ol>
<li>In your favorite text editor, create an HTML file
(for example, <code>helloworld.html</code>).</li>
<li>From the <strong>Source</strong> box below, copy and paste the code into your HTML file.
(Double-click on the source to easily select all.)</li>
<li>Open the file in your web browser.</li>
</ol><doc:example>
<pre class="doc-source">
Hello {{'World'}}!
</pre>
</doc:example><p>The resulting web page should look something like the following:</p>
<p><img class="center" src="img/helloworld.png" border="1" /></p>
<p>Now let's take a closer look at that code, and see what is going on behind
the scenes.</p>
<p>The first line of interest defines the <code>ng</code> namespace, which makes
AngularJS work across all browsers (especially important for IE):</p><div ng:non-bindable><pre class="brush: js; html-script: true;">
<html xmlns:ng="http://angularjs.org">
</pre></div><p>The next line downloads the angular script, and instructs angular to process
the entire HTML page when it is loaded:</p><div ng:non-bindable><pre class="brush: js; html-script: true;">
<script type="text/javascript" src="http://code.angularjs.org/angular-?.?.?.min.js"
ng:autobind></script>
</pre></div><p>(For details on what happens when angular processes an HTML page,
see <a href="#!/guide/dev_guide.bootstrap">Bootstrap</a>.)</p>
<p>Finally, this line in the <code><body></code> of the page is the template that describes
how to display our greeting in the UI:</p><div ng:non-bindable><pre class="brush: js;">
Hello {{'World'}}!
</pre></div><p>Note the use of the double curly brace markup (<code>{{ }}</code>) to bind the expression to
the greeting text. Here the expression is the string literal 'World'.</p>
<p>Next let's look at a more interesting example, that uses AngularJS to
bind a dynamic expression to our greeting text.</p>
<h2>Hello AngularJS World!</h2>
<p>This example demonstrates angular's two-way data binding:</p>
<ol>
<li>Edit the HTML file you created in the "Hello World!" example above.</li>
<li>Replace the contents of <code><body></code> with the code from the <strong>Source</strong> box below.</li>
<li>Refresh your browser window.</li>
</ol><doc:example>
<pre class="doc-source">
Your name: <input type="text" name="yourname" value="World"/>
<hr/>
Hello {{yourname}}!
</pre>
</doc:example><p>After the refresh, the page should look something like this:</p>
<p><img class="left" src="img/helloworld_2way.png" border="1" /></p>
<p>These are some of the important points to note from this example:</p>
<ul>
<li>The text input <a href="#!/api/angular.widget"><code>widget</code></a> called <code>yourname</code> is bound to a model variable
called <code>yourname</code>.</li>
<li><p>The double curly braces notation binds the <code>yourname</code> model to the greeting text.</p></li>
<li><p>You did not need to explicitly register an event listener or define an event handler for events!</p></li>
</ul>
<p>Now try typing your name into the input box, and notice the immediate change to
the displayed greeting. This demonstrates the concept of angular's
<a href="#!/guide/dev_guide.templates.databinding">bi-directional data binding</a>. Any changes to the input
field are immediately
reflected in the model (one direction), and any changes to the model are
reflected in the greeting text (the other direction).</p>
<h2>Anatomy Of An Angular App</h2>
<p>This section describes the 3 parts of an angular app, and explains how they map to the
Model-View-Controller design pattern:</p>
<h3>Templates</h3>
<p>Templates, which you write in HTML and CSS, serve as the View. You add elements, attributes, and
markup to HTML, which serve as instructions to the angular compiler. The angular compiler is fully
extensible, meaning that with angular you can build your own declarative language on top of HTML!</p>
<h3>Application Logic and Behavior</h3>
<p>Application Logic and Behavior, which you define in JavaScript, serve as the Controller. With
angular (unlike with standard AJAX applications) you don't need to write additional listeners or
DOM manipulators, because they are built-in. This feature makes your application logic very easy to
write, test, maintain, and understand.</p>
<h3>Data</h3>
<p>The Model is referenced from properties on <a href="#!/guide/dev_guide.scopes">angular scope objects</a>.
The data in your model could be Javascript objects, arrays, or primitives, it doesn't matter. What
matters is that these are all referenced by the scope object.</p>
<p>Angular employs scopes to keep your data model and your UI in sync. Whenever something occurs to
change the state of the model, angular immediately reflects that change in the UI, and vice versa.</p>
<p>The following illustration shows the parts of an angular application and how they work together:</p>
<p><img class="left" src="img/angular_parts.png" border="0" /></p>
<p>In addition, angular comes with a set of Services, which have the following properties:</p>
<ul>
<li>The services provided are very useful for building web applications.</li>
<li>You can extend and add application-specific behavior to services.</li>
<li>Services include Dependency-Injection, XHR, caching, URL routing, and browser abstraction.</li>
</ul>
<h2>Where To Go Next</h2>
<ul>
<li><p>If you like what you've learned so far, you should definitely check out our awesome <a href="#!/tutorial/index">Tutorial</a>, which walk you through the process of building real apps with AngularJS.</p></li>
<li><p>For further explanations and examples of the AngularJS concepts presented on this page, see the
<a href="#!/guide/index">Developer Guide</a>.</p></li>
<li><p>For additional hands-on examples of using AngularJS, including more source code that you can
copy and paste into your own pages, take a look through the <a href="#!/cookbook/index">Cookbook</a>.</p></li>
</ul></div>