@@ -13,23 +13,25 @@ details for any device.
13
13
<img class="diagram" src="img/tutorial/catalog_screen.png" width="488" height="413" alt="demo
14
14
application running in the browser">
15
15
16
- Work through the tutorial to see how Angular makes browsers smarter — without the use of native
17
- extensions or plug-ins. As you work through the tutorial, you will :
16
+ Follow the tutorial to see how Angular makes browsers smarter — without the use of native
17
+ extensions or plug-ins:
18
18
19
- * See examples of how to use client-side data binding and dependency injection to build dynamic
20
- views of data that change immediately in response to user actions.
21
- * See how Angular creates listeners on your data without the need for DOM manipulation.
22
- * Learn a better, easier way to test your web apps.
23
- * Learn how to use Angular services to make common web tasks, such as getting data into your app,
24
- easier.
19
+ * See examples of how to use client-side data binding to build dynamic views of data that change
20
+ immediately in response to user actions.
21
+ * See how Angular keeps your views in synch with your data without the need for DOM manipulation.
22
+ * Learn a better, easier way to test your web apps, with Karma and Protractor .
23
+ * Learn how to use dependency injection and services to make common web tasks, such as getting data
24
+ into your app, easier.
25
25
26
26
When you finish the tutorial you will be able to:
27
27
28
28
* Create a dynamic application that works in all modern browsers.
29
- * Define the differences between Angular and common JavaScript frameworks.
30
- * Understand how data binding works in AngularJS.
31
- * Create and run unit tests.
32
- * Create and run end to end tests.
29
+ * Use data binding to wire up your data model to your views.
30
+ * Create and run unit tests, with Karma.
31
+ * Create and run end to end tests, with Protractor.
32
+ * Move application logic out of the template and into Controllers.
33
+ * Get data from a server using Angular services.
34
+ * Apply animations to your application, using ngAnimate.
33
35
* Identify resources for learning more about AngularJS.
34
36
35
37
The tutorial guides you through the entire process of building a simple application, including
@@ -40,31 +42,46 @@ You can go through the whole tutorial in a couple of hours or you may want to sp
40
42
really digging into it. If you're looking for a shorter introduction to AngularJS, check out the
41
43
{@link misc/started Getting Started} document.
42
44
45
+ # Get Started
43
46
47
+ The rest of this page explains how you can set up your machine to work with the code on your local
48
+ machine. If you just want to read the tutorial then you can just go straight to the first step:
49
+ [Step 0 - Bootstrapping](tutorial/step_00).
44
50
45
51
# Working with the code
46
52
47
- You can follow along with this tutorial and hack on the code in either the Mac/Linux or the Windows
48
- environment. The tutorial relies on the use of the [Git][git] versioning system for source code
49
- management.
53
+ You can follow along with this tutorial and hack on the code in the comfort of your own computer.
54
+ In this way you can get hands-on practice of really writing AngularJS code and also on using the
55
+ recommended testing tools.
56
+
57
+ The tutorial relies on the use of the [Git][git] versioning system for source code management.
58
+ You don't need to know anything about Git to follow the tutorial other than how to install and run
59
+ a few git commands.
50
60
51
- You don't need to know anything about Git to follow the tutorial. Select one of the tabs below
52
- and follow the instructions for setting up your computer.
53
61
62
+ ### Install Git
54
63
55
- ## Install Git
64
+ You can download and install Git from http://git-scm.com/download. Once installed you should have
65
+ access to the `git` command line tool. The main commands that you will need to use are:
56
66
57
- You'll need Git, which you can get from [the Git site][git].
67
+ - `git clone ...` : clone a remote repository onto your local machine
68
+ - `git checkout ...` : check out a particular branch or a tagged version of the code to hack on
69
+
70
+ ### Download angular-phonecat
58
71
59
72
Clone the [angular-phonecat repository][angular-phonecat] located at GitHub by running the following
60
73
command:
61
74
62
75
```
63
- git clone https://github.com/angular/angular-phonecat.git
76
+ git clone --depth=14 https://github.com/angular/angular-phonecat.git
64
77
```
65
78
66
79
This command creates the `angular-phonecat` directory in your current directory.
67
80
81
+ <div class="alert alert-info">The `--depth=14` option just tells Git to pull down only the last 14 commits. This makes the
82
+ download much smaller and faster.
83
+ </div>
84
+
68
85
Change your current directory to `angular-phonecat`.
69
86
70
87
```
@@ -75,118 +92,144 @@ The tutorial instructions, from now on, assume you are running all commands from
75
92
`angular-phonecat` directory.
76
93
77
94
78
- ## Install Node.js
79
-
80
- If you want to run the built-in web-server and the test tools then you will also need
81
- Node.js v0.10, or later.
95
+ ### Install Node.js
82
96
83
- You can download Node.js from the [node.js website][node].
97
+ If you want to run the preconfigured local web-server and the test tools then you will also need
98
+ [Node.js v0.10+][node].
84
99
100
+ You can download a Node.js installer for your operating system from http://nodejs.org/download/.
85
101
86
- You can check the version of Node.js that you have installed by running the following command:
102
+ Check the version of Node.js that you have installed by running the following command:
87
103
88
104
```
89
105
node --version
90
106
```
91
107
92
- <div class="alert alert-info"><strong>Helpful note:<strong> If you need to run a different versions of node.js
108
+ <div class="alert alert-info">If you need to run a different versions of node.js
93
109
in your local environment, consider installing
94
110
<a href="https://github.com/creationix/nvm" title="Node Version Manager Github Repo link">
95
111
Node Version Manager (nvm)
96
112
</a>.
97
113
</div>
98
114
99
- Once you have Node.js installed you can install the tool dependencies by running:
115
+ Once you have Node.js installed on your machine you can download the tool dependencies by running:
100
116
101
117
```
102
118
npm install
103
119
```
104
120
105
- This command will download the following tools, into the `node_modules` directive :
121
+ This command will download the following tools, into the `node_modules` directory :
106
122
107
123
- [Bower][bower] - client-side code package manager
108
- - [http-server ][http-server] - simple local static web server
124
+ - [Http-Server ][http-server] - simple local static web server
109
125
- [Karma][karma] - unit test runner
110
- - [protractor ][protractor] - end 2 end test runner
126
+ - [Protractor ][protractor] - end 2 end test runner
111
127
112
128
Running `npm install` will also automatically run `bower install`, which will download the Angular
113
129
framework into the `bower_components` directory.
114
130
115
131
The project is preconfigured with a number of npm helper scripts to make it easy to run the common
116
- tasks that you will need while developing.
132
+ tasks that you will need while developing:
133
+
134
+ - `npm start` : start a local development web-server
135
+ - `npm test` : start the Karma unit test runner
136
+ - `npm run protractor` : run the Protractor end 2 end tests
137
+ - `npm update-webdriver` : install the drivers needed by Protractor
117
138
118
- ## Running Development Web Server
139
+ ### Running Development Web Server
119
140
120
- The project is preconfigured to provide a simple static web server for hosting the application.
121
- Start the web server by running:
141
+ While Angular applications are purely client-side code, and it is possible to open them in a web
142
+ browser directly from the file system, it is better to server them from a HTTP web server. In
143
+ particular, for security reasons, most modern browsers will not allow JavaScript to make server
144
+ requests if the page is loaded directly from the file system.
145
+
146
+ The angular-phonecat project is configured with a simple static web server for hosting the
147
+ application during development. Start the web server by running:
122
148
123
149
```
124
150
npm start
125
151
```
126
152
127
- Now you can browse to the application at:
153
+ This will create a local webserver that is listening to port 8000 on your local machine.
154
+ You can now browse to the application at:
128
155
129
156
```
130
157
http://localhost:8000/app/index.html
131
158
```
132
159
133
- ## Running Unit Tests
160
+ ### Running Unit Tests
161
+
162
+ We use unit tests to ensure that the JavaScript code in our application is operating correctly.
163
+ Unit tests focus on testing small isolated parts of the application. The unit tests are kept in the
164
+ `test/unit` directory.
134
165
135
- The project is preconfigured to use [Karma][karma] to run the unit tests for the application. Start
136
- Karma by running:
166
+ The angular-phonecat project is configured to use [Karma][karma] to run the unit tests for the
167
+ application. Start Karma by running:
137
168
138
169
```
139
170
npm test
140
171
```
141
172
142
- This will start the Karma unit test runner, open up a Chrome browser and execute all the unit tests
143
- in this browser. Karma will then sit and watch all the source and test JavaScript files.
144
- Whenever one of these files changes Karma re-runs all the unit tests.
173
+ This will start the Karma unit test runner. Karma will read the configuration file at
174
+ `test/karma.conf.js`. This configuration file tells Karma to:
145
175
146
- It is good to leave this running all the time as you will get immediate feedback from Karma as you
147
- are working on the code.
176
+ - open up a Chrome browser and connect it to Karma
177
+ - execute all the unit tests in this browser
178
+ - report the results of these tests in the terminal/command line window
179
+ - watch all the project's JavaScript files and re-run the tests whenever any of these change
148
180
181
+ It is good to leave this running all the time, in the background, as it will give you immediate
182
+ feedback about whether your changes pass the unit tests while you are working on the code.
149
183
150
- ## Running End to End Tests
151
184
152
- The project is preconfigured to use [Protractor][protractor] to run the end to end tests for the
153
- application. Set up the binaries protractor needs to run by running:
185
+ ### Running End to End Tests
154
186
155
- ```
156
- npm run update-webdriver
157
- ```
158
- (You will only need to do this once) Execute the Protractor test scripts against your application
159
- by running:
187
+ We use End to End tests to ensure that the application as a whole operates as expected.
188
+ End to End tests are designed to test the whole client side application, in particular that the
189
+ views are displaying and behaving correctly. It does this by simulating real user interaction with
190
+ the real application running in the browser.
191
+
192
+ The End to End tests are kept in the `test/e2e` directory.
193
+
194
+ The angular-phonecat project is configured to use [Protractor][protractor] to run the End to End
195
+ tests for the application. Protractor relies upon a set of drivers to allow it to interact with
196
+ the browser. You can install these drivers by running:
160
197
161
198
```
162
- npm run protractor
199
+ npm run update-webdriver
163
200
```
164
201
165
- This will start the Protractor end to end test runner, open up a Chrome browser and execute all the
166
- end to end test scripts in this browser. Once the test scripts finish, the browser will close down
167
- and Protractor will exit.
202
+ *(You should only need to do this once.)*
168
203
169
- It is good to run the end to end tests whenever you make changes to the HTML views or want to check
170
- that the application as a whole is executing correctly.
204
+ Since Protractor works by interacting with a running application, we need to start our web server:
171
205
172
- <div class="alert alert-info"><strong>Helpful note:</strong> Protractor requires that a web server is running
173
- and serving up the application at the default URL: `http://localhost:8000/app/index.html`. You can
174
- start the provided development server by running `npm start`.
175
- </div>
206
+ ```
207
+ npm start
208
+ ```
176
209
210
+ Then in a separate terminal/command line window, we can run the Protractor test scripts against the
211
+ application by running:
177
212
178
- # Get Started
213
+ ```
214
+ npm run protractor
215
+ ```
179
216
180
- Now your environment is ready, it is time to get started developing the Angular PhoneCat
181
- application.
217
+ Protractor will read the configuration file at `test/protractor-conf.js`. This configuration tells
218
+ Protractor to:
182
219
183
- <a href="tutorial/step_00" title="Next Step"><span class="btn btn-primary">Step 0 - Bootstrapping</span></a>
220
+ - open up a Chrome browser and connect it to the application
221
+ - execute all the End to End tests in this browser
222
+ - report the results of these tests in the terminal/command line window
223
+ - close down the browser and exit
184
224
225
+ It is good to run the end to end tests whenever you make changes to the HTML views or want to check
226
+ that the application as a whole is executing correctly. It is very common to run End to End tests
227
+ before pushing a new commit of changes to a remote repository.
185
228
186
229
187
- [git]: http://git-scm.com/download
188
- [angular-phonecat]: https://github.com/angular/angular-phonecat
230
+ [git]: http://git-scm.com/
189
231
[node]: http://nodejs.org/
232
+ [angular-phonecat]: https://github.com/angular/angular-phonecat
190
233
[protractor]: https://github.com/angular/protractor
191
234
[bower]: http://bower.io/
192
235
[http-server]: https://github.com/nodeapps/http-server
0 commit comments