From 9d9117384f7879be56e5b905f3533b89983efa4b Mon Sep 17 00:00:00 2001
From: Kenneth R. Culp
Date: Mon, 2 May 2011 16:40:31 -0700
Subject: Latest greatest tutorial udpates.
---
docs/content/tutorial/index.ngdoc | 47 ++++++++++++----------
docs/content/tutorial/step_00.ngdoc | 19 ++++-----
docs/content/tutorial/step_01.ngdoc | 17 ++++++--
docs/content/tutorial/step_02.ngdoc | 80 ++++++++++++++++++++++++++-----------
docs/content/tutorial/step_03.ngdoc | 59 ++++++++++++++++++++-------
docs/content/tutorial/step_04.ngdoc | 49 +++++++++++++++--------
docs/content/tutorial/step_05.ngdoc | 65 ++++++++++++++++++------------
docs/content/tutorial/step_06.ngdoc | 22 +++++++---
docs/content/tutorial/step_07.ngdoc | 58 ++++++++++++++++++---------
docs/content/tutorial/step_08.ngdoc | 43 ++++++++++++--------
docs/content/tutorial/step_09.ngdoc | 43 ++++++++++++++------
docs/content/tutorial/step_10.ngdoc | 41 ++++++++++++++-----
docs/content/tutorial/step_11.ngdoc | 38 +++++-------------
13 files changed, 379 insertions(+), 202 deletions(-)
(limited to 'docs/content')
diff --git a/docs/content/tutorial/index.ngdoc b/docs/content/tutorial/index.ngdoc
index efe30573..85c84260 100644
--- a/docs/content/tutorial/index.ngdoc
+++ b/docs/content/tutorial/index.ngdoc
@@ -18,10 +18,10 @@ developing a typical web app. For this tutorial, we modified the angular-seed as
* Removed the example app
* Added phone images to `app/img/phones`
-* Added phone data files (JSON) to `app/phones`
+* Added phone data files (JSON) to `app/phones`
- Note: Using the angular seed app isn't required for building angular apps, but doing so helps
- you get started quickly and makes the development and testing process much easier.
+**Note**: Using the angular seed app isn't required for building angular apps, but doing so helps
+you get started quickly and makes the development and testing process much easier.
When you finish the tutorial you will be able to:
@@ -46,36 +46,38 @@ To run the tutorial app and tests on your machine you will need the following:
* A Mac or Linux machine (required by the tutorial scripts, not angular)
* An http server running on your system. If you don't already have one installed, you can install
-`node.js` ({@link https://github.com/joyent/node/wiki/Installation node.js install}) or another
-http sever (such as Apache, etc.).
-* Java. This is only required for if you want to run tests via JsTestDriver.
+`node.js` ({@link https://github.com/joyent/node/wiki/Installation node.js install guide}) or
+another http sever (such as Apache, etc.).
+* Java. This is required for running tests with JsTestDriver.
* A web browser.
* A text editor.
-# Using Git
-The following instructions are for developers who are comfortable with Git versioning system:
+# Working with the code
+
+There are two ways that you can you follow this tutorial and hack on the code:
+
+## Using Git
+
+The following instructions are for developers who are comfortable with the Git versioning system:
1. Check to be sure you have all of the prerequisites on your system.
2. Clone the angular-phonecat repository located at {@link
-https://github.com/angular/angular-phonecat angular-phonecat} by running the following command in
-a terminal:
+https://github.com/angular/angular-phonecat GitHub} by running the following command in a terminal:
- git clone git://github.com/angular/angular-phonecat.git
+ git clone git://github.com/angular/angular-phonecat.git
This will create a directory called `angular-phonecat` in the current directory.
3. Change your current directory to `angular-phonecat`.
- cd angular-phonecat
+ cd angular-phonecat
The tutorial instructions assume you are running all commands from this directory.
-Read the Tutorial Navigation section, then navigate to Step 0.
-
-# Using Snapshots
+## Using Snapshots
Snapshots are the sets of files that reflect the state of the tutorial app at each step. These
files include the HTML, CSS, and JavaScript for the app, plus Jasmine JavaScript files and Java
@@ -84,18 +86,21 @@ knowledge of Git. You can download and install the snapshot files as follows:
1. Check to be sure you have all of the prerequisites on your system.
-2. Navigate to [*the angular server*], download and then unzip [*the snapshot file*] to an
-[*install-dir*].
+2. {@link TODO Download the zip archive} with all files and unzip them into `[tutorial-dir]`
+directory.
-3. Change directories to [*install-dir*]/sandbox.
- cd [*install-dir*]/sandbox
+3. Change directories to `[tutorial-dir]/sandbox`.
+
+ cd [tutorial-dir]/sandbox
-Read the Tutorial Navigation section, then navigate to step-0.
# Tutorial Navigation
To see the app running on the angular server, click the "Live Demo" link at the top or bottom of
any tutorial page. To view the code differences between tutorial steps, click the Code Diff link
at top or bottom of each tutorial page. In the Code Diff, additions are highlighted in green;
-deletions are highlighted in red.
+deletions are highlighted in red.
+
+
+Let's get going and proceed to {@link tutorial/step_00 step 0}.
diff --git a/docs/content/tutorial/step_00.ngdoc b/docs/content/tutorial/step_00.ngdoc
index a6dc1ca9..b03d2ec6 100755
--- a/docs/content/tutorial/step_00.ngdoc
+++ b/docs/content/tutorial/step_00.ngdoc
@@ -8,13 +8,13 @@
{@link http://angular.github.com/angular-phonecat/step-0/app Live Demo}
{@link tutorial Tutorial Home}
Code Diff
-
{@link tutorial.step_0 Next}
+
{@link tutorial.step_01 Next}
You are now ready to build the phone cat application. In this step, you will become familiar with
-the most important source code files, learn how to start the web services, and run the application
-in the browser.
+the most important source code files, learn how to start the development servers bundled with
+angular-seed, and run the application in the browser.
1. Do one of the following:
@@ -22,11 +22,11 @@ in the browser.
git checkout step-0
- * Snapshot users: In the `[install directory]/sandbox` directory, run this command:
+ * Snapshot users: In the `[tutorial-dir]/sandbox` directory, run this command:
./goto_step.sh 0
-This resets your workspace to Step 0 of the tutorial app.
+ This resets your workspace to Step 0 of the tutorial app.
2. To see the app running in a browser, do one of the following:
* __For node.js users:__
@@ -36,8 +36,7 @@ This resets your workspace to Step 0 of the tutorial app.
* __For other http servers:__
1. Configure the server to serve the files in the `angular-phonecat` directory.
- 2. Run `./scripts/web-server.js` to start the app server.
- 3. Navigate in your browser to
+ 2. Navigate in your browser to
http://localhost:[*port-number*]/[*context-path*]/app/index.html.
You can now see the app in the browser. It's not very exciting, but that's OK.
@@ -75,9 +74,11 @@ versions older than 9 (regardless of whether you are using XHTML or HTML).
registers a callback that will be executed by the browser when the containing HTML page is fully
downloaded. When the callback is executed, angular looks for the {@link
angular.directive.ng:autobind ng:autobind} attribute. If `ng:autobind` is found, it signals
-angular to bootstrap and compile and manage the whole html page.
+angular to bootstrap, compile, and manage the whole html page.
+
+# Summary
-Now let's go to Step 1 and add some content to the web app.
+Now let's go to step 1 and add some content to the web app.
diff --git a/docs/content/tutorial/step_01.ngdoc b/docs/content/tutorial/step_01.ngdoc
index b9c171d2..4f0640c9 100755
--- a/docs/content/tutorial/step_01.ngdoc
+++ b/docs/content/tutorial/step_01.ngdoc
@@ -15,7 +15,7 @@
In this step you will add some basic information about two cell phones to our app.
-1. Do one of the following to reset your workspace to Step 1; be aware that this will throw away
+1. Do one of the following to reset your workspace to step 1; be aware that this will throw away
any changes you might have made to the tutorial files:
* Git users run:
@@ -27,8 +27,8 @@ any changes you might have made to the tutorial files:
./goto_step.sh 1
2. Refresh your browser or check the app out on {@link
-http://angular.github.com/angular-phonecat/step-1/app, our server}. Your page now contains a list
-with information about two phones.
+http://angular.github.com/angular-phonecat/step-1/app anglar's server}. The page now contains a
+list with information about two phones.
The most important changes are listed below. You can see the full diff on {@link
https://github.com/angular/angular-phonecat/compare/step-0...step-1 GitHub}:
@@ -53,7 +53,16 @@ __`app/index.html`:__
...
-This addition to your app uses static HTML to display the list. Now, let's go to Step 2 to learn
+# Experiments
+
+* Try adding more static html to `index.html`. For example:
+
+
Total number of phones: 3
+
+
+# Summary
+
+This addition to your app uses static HTML to display the list. Now, let's go to step 2 to learn
how to use angular to dynamically generate the same list.
diff --git a/docs/content/tutorial/step_02.ngdoc b/docs/content/tutorial/step_02.ngdoc
index 143e310a..fdf881b0 100755
--- a/docs/content/tutorial/step_02.ngdoc
+++ b/docs/content/tutorial/step_02.ngdoc
@@ -21,16 +21,17 @@ of {@link http://en.wikipedia.org/wiki/Model–View–Controller the MVC design
the code and separate concerns. With that in mind, let's use a little angular and JavaScript to
add Model, View, and Controller components to our app.
-1. Reset your workspace to Step 2 using:
+1. Reset your workspace to step 2 using:
- git checkout --force step-2
- or
+ git checkout --force step-2
- ./goto_step.sh 2
+ or
+
+ ./goto_step.sh 2
2. Refresh your browser or check the app out on {@link
-http://angular.github.com/angular-phonecat/step-2/app our server}. The app now contains a list
-with 3 phones.
+http://angular.github.com/angular-phonecat/step-2/app angular's server}. The app now contains a
+list with 3 phones.
The most important changes are listed below. You can see the full diff on {@link
https://github.com/angular/angular-phonecat/compare/step-1...step-2 GitHub}:
@@ -67,9 +68,9 @@ and `{{phone.snippet}}`:
`
` tag as the template.
* The curly braces around `phone.name` and `phone.snippet` are an example of {@link
- angular.markup angular markup}. The curly braces are shorthand for the angular directive
- {@link angular.directive.ng:bind ng:bind}. They indicate to angular that these are template
- binding points. Binding points are locations in the template where angular creates
+ angular.markup angular markup}. The curly markup is shorthand for the angular directive {@link
+ angular.directive.ng:bind ng:bind}. `ng:bind` directives indicates to angular that these are
+ template binding points. Binding points are locations in the template where angular creates
data-binding between the View and the Model. In angular, the View is a projection of the Model
through the HTML template. This means that whenever the model changes, angular refreshes the
appropriate binding points, which updates the view.
@@ -102,7 +103,7 @@ data, and logic components:
(`PhoneListCtrl`).
* We instantiated our data within the scope of our controller function, and our template
binding points are located within the block bounded by the `` tag.
Angular uses scopes, along with the information contained in the template, data model, and
controller to keep the Model and View separated but in sync: any changes to the model are
@@ -139,26 +140,59 @@ writing tests. Although Jasmine is not required by angular, we used it to write
tutorial. You can learn about Jasmine on the {@link http://pivotal.github.com/jasmine/ Jasmine
home page} and on the {@link https://github.com/pivotal/jasmine/wiki Jasmine wiki}.
-angular-seed project is pre-configured to run all unit tests using {@link
+The angular-seed project is pre-configured to run all unit tests using {@link
http://code.google.com/p/js-test-driver/ JsTestDriver}. To run the test, do the following:
- 1. In a _separate_ terminal window or tab, go to the `angular-phonecat` directory and run
- `./scripts/test-server.sh` to start the test web server.
+1. In a _separate_ terminal window or tab, go to the `angular-phonecat` directory and run
+`./scripts/test-server.sh` to start the test web server.
+
+2. Open a new browser tab or window, navigate to http://localhost:9876, and choose "strict mode".
+At this point, you can leave this tab open and forget about it. JsTestDriver will use it to
+execute our tests and report the results in the terminal.
+
+3. Execute the test by running `./scripts/test.sh`
+
+ You should see the following or similar output:
+
+ Chrome: Runner reset.
+ .
+ Total 1 tests (Passed: 1; Fails: 0; Errors: 0) (2.00 ms)
+ Chrome 11.0.696.57 Mac OS: Run 1 tests (Passed: 1; Fails: 0; Errors 0) (2.00 ms)
+
+ Yay! The test passed!
+
+# Experiments
+
+* Add another binding to `index.html`. For example:
+
+
Total number of phones: {{phones.length}}
+
+* Create a new model property in the controller and bind to it from the template. For example:
+
+ this.hello = "Hello, World!"
+
+* Create a repeater that constructs a simple table:
+
+
+
row number
+
{{i}}
+
+
+ Now, make the list 1-based by incrementing `i` by one in the binding:
- 2. Open a new browser tab or window, navigate to http://localhost:9876, and choose "strict
- mode". At this point, you can leave this tab open and forget about it. JsTestDriver will
- use it to execute our tests and report the results in the terminal.
+
+
row number
+
{{i+1}}
+
- 3. Execute the test by running `./scripts/test.sh`
+* Make the unit test fail by changing the `toBe(3)` statement to `toBe(4)`, and rerun the
+`./scripts/test.sh` script.
-You should see the following or similar output:
- Chrome: Runner reset.
- .
- Total 1 tests (Passed: 1; Fails: 0; Errors: 0) (2.00 ms)
- Chrome 11.0.696.57 Mac OS: Run 1 tests (Passed: 1; Fails: 0; Errors 0) (2.00 ms)
+# Summary
-Yay! The test passed! Now, let's go to Step 3 to learn how to add full text search to the app.
+You now have a dynamic app that features separate model, view, and controller components, and
+you're testing as you go. Now, let's go to step 3 to learn how to add full text search to the app.
diff --git a/docs/content/tutorial/step_03.ngdoc b/docs/content/tutorial/step_03.ngdoc
index 812f58bb..53eaebc8 100755
--- a/docs/content/tutorial/step_03.ngdoc
+++ b/docs/content/tutorial/step_03.ngdoc
@@ -20,15 +20,15 @@ eye on it, and quickly detects regressions.
1. Reset your workspace to Step 3 using:
- git checkout --force step-3
+ git checkout --force step-3
- or
+ or
- ./goto_step.sh 3
+ ./goto_step.sh 3
2. Refresh your browser or check the app out on {@link
-http://angular.github.com/angular-phonecat/step-3/app our server}. The app now has a search box.
-The phone list on the page changes depending on what a user types into the search box.
+http://angular.github.com/angular-phonecat/step-3/app angular's server}. The app now has a search
+box. The phone list on the page changes depending on what a user types into the search box.
The most important changes are listed below. You can see the full diff on {@link
https://github.com/angular/angular-phonecat/compare/step-2...step-3
@@ -71,15 +71,15 @@ sync.
When changes to the data model cause the repeater's input to change, the repeater efficiently
updates the DOM to reflect the current state of the model.
-* Use of `$filter`. The `{@link angular.Array.filter $filter}` method, uses the `query` value, to
+* Use of `$filter`. The {@link angular.Array.filter $filter} method, uses the `query` value, to
create a new array that contains only those records that match the `query`.
-* `ng:repeat` automatically updates the view in response to the changing number of phones returned
-by the `$filter`. The process is completely transparent to the developer.
+ `ng:repeat` automatically updates the view in response to the changing number of phones returned
+ by the `$filter`. The process is completely transparent to the developer.
## Test
-In Step 2, we learned how to write and run unit tests. Unit tests are perfect for testing
+In step 2, we learned how to write and run unit tests. Unit tests are perfect for testing
controllers and other components of our application written in JavaScript, but they can't easily
test DOM manipulation or the wiring of our application. For these, an end-to-end test is a much
better choice.
@@ -117,17 +117,48 @@ angular's end-to-end test runner}.
To run the end-to-end test, open the following in a new browser tab:
-* node.js users: http://localhost:8000/test/e2e/runner.html
+* node.js users: {@link http://localhost:8000/test/e2e/runner.html}
* users with other http servers:
-http://localhost:[*port-number*]/[*context-path*]/test/e2e/runner.html
-* casual reader: http://angular.github.com/angular-phonecat/step-3/test/e2e/runner.html
+`http://localhost:[*port-number*]/[*context-path*]/test/e2e/runner.html`
+* casual reader: {@link http://angular.github.com/angular-phonecat/step-3/test/e2e/runner.html}
This test verifies that the search box and the repeater are correctly wired together. Notice how
easy it is to write end-to-end tests in angular. Although this example is for a simple test, it
really is that easy to set up any functional, readable, end-to-end test.
-Now that you've verified everything, go to Step 4 to learn how to add sorting capability to the
-phone list app.
+# Experiments
+
+* Display the current value of the `query` model by adding a `{{query}}` binding into the
+`index.html` template, and see how it changes when you type in the input box.
+
+* Change `index.html` to reflect the current search query in the html title by replacing the title
+tag in the head section with:
+
+ Google Phone Gallery: {{query}}`
+
+ If you reload the page, you won't see the expected result. This is because the "query" model
+ lives in the scope defined by:
+
+
+
+ In order to be able to bind to the query mode from ``, we need to move the
+ `ng:controller` declaration to an element that is a common parent for both the body and title
+ elements. In our case that's the html element:
+
+
+
+* Make the end-to-end test fail by changing the first `toBe(3)` statement to `toBe(4)`, and
+refresh the end-to-end test runner tab in the browser to rerun the test.
+* Add a `wait();` statement into the end-to-end test and rerun it. You'll see the runner pausing,
+giving you the opportunity to explore the state of your application displayed in the browser. The
+app is live! Change the search query to prove it. This is great for troubleshooting end-to-end
+tests.
+
+
+# Summary
+
+With full text search under our belt and a test to verify it, let's go to step 4 to learn how to
+add sorting capability to the phone app.
-In this step, you will add a feature to let your users select the order of the items in the phone
+In this step, you will add a feature to let your users control the order of the items in the phone
list. The dynamic ordering is implemented by creating a new model property, wiring it together
with the repeater, and letting the data binding magic do the rest of the work.
1. Reset your workspace to Step 4 using:
- git checkout --force step-4
+ git checkout --force step-4
-or
+ or
- ./goto_step.sh 4
+ ./goto_step.sh 4
2. Refresh your browser or check the app out on {@link
-http://angular.github.com/angular-phonecat/step-4/app our server}. You should see that in addition
-to the search box, the app displays a drop down menu that allows users to control the order in
-which the phones are listed.
+http://angular.github.com/angular-phonecat/step-4/app angular's server}. You should see that in
+addition to the search box, the app displays a drop down menu that allows users to control the
+order in which the phones are listed.
The most important changes are listed below. You can see the full diff on {@link
https://github.com/angular/angular-phonecat/compare/step-3...step-4
@@ -67,13 +67,14 @@ In the `index.html` template we made the following changes:
* First, we added a `