@@ -21,16 +21,17 @@ of {@link http://en.wikipedia.org/wiki/Model–View–Controller the MVC design
2121the code and separate concerns. With that in mind, let's use a little angular and JavaScript to
2222add Model, View, and Controller components to our app.
2323
24- 1. Reset your workspace to Step 2 using:
24+ 1. Reset your workspace to step 2 using:
2525
26- git checkout --force step-2
27- or
26+ git checkout --force step-2
2827
29- ./goto_step.sh 2
28+ or
29+
30+ ./goto_step.sh 2
3031
31322. Refresh your browser or check the app out on {@link
32- http://angular.github.com/angular-phonecat/step-2/app our server}. The app now contains a list
33- with 3 phones.
33+ http://angular.github.com/angular-phonecat/step-2/app angular's server}. The app now contains a
34+ list with 3 phones.
3435
3536The most important changes are listed below. You can see the full diff on {@link
3637https://github.com/angular/angular-phonecat/compare/step-1...step-2 GitHub}:
@@ -67,9 +68,9 @@ and `{{phone.snippet}}`:
6768 `<li>` tag as the template.
6869
6970 * The curly braces around `phone.name` and `phone.snippet` are an example of {@link
70- angular.markup angular markup}. The curly braces are shorthand for the angular directive
71- {@link angular.directive.ng:bind ng:bind}. They indicate to angular that these are template
72- binding points. Binding points are locations in the template where angular creates
71+ angular.markup angular markup}. The curly markup is shorthand for the angular directive {@link
72+ angular.directive.ng:bind ng:bind}. `ng:bind` directives indicates to angular that these are
73+ template binding points. Binding points are locations in the template where angular creates
7374 data-binding between the View and the Model. In angular, the View is a projection of the Model
7475 through the HTML template. This means that whenever the model changes, angular refreshes the
7576 appropriate binding points, which updates the view.
@@ -102,7 +103,7 @@ data, and logic components:
102103 (`PhoneListCtrl`).
103104 * We instantiated our data within the scope of our controller function, and our template
104105 binding points are located within the block bounded by the `<body
105- ng:controller="PhoneListCtrl>` tag.
106+ ng:controller="PhoneListCtrl" >` tag.
106107
107108 Angular uses scopes, along with the information contained in the template, data model, and
108109 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
139140tutorial. You can learn about Jasmine on the {@link http://pivotal.github.com/jasmine/ Jasmine
140141home page} and on the {@link https://github.com/pivotal/jasmine/wiki Jasmine wiki}.
141142
142- angular-seed project is pre-configured to run all unit tests using {@link
143+ The angular-seed project is pre-configured to run all unit tests using {@link
143144http://code.google.com/p/js-test-driver/ JsTestDriver}. To run the test, do the following:
144145
145- 1. In a _separate_ terminal window or tab, go to the `angular-phonecat` directory and run
146- `./scripts/test-server.sh` to start the test web server.
146+ 1. In a _separate_ terminal window or tab, go to the `angular-phonecat` directory and run
147+ `./scripts/test-server.sh` to start the test web server.
148+
149+ 2. Open a new browser tab or window, navigate to http://localhost:9876, and choose "strict mode".
150+ At this point, you can leave this tab open and forget about it. JsTestDriver will use it to
151+ execute our tests and report the results in the terminal.
152+
153+ 3. Execute the test by running `./scripts/test.sh`
154+
155+ You should see the following or similar output:
156+
157+ Chrome: Runner reset.
158+ .
159+ Total 1 tests (Passed: 1; Fails: 0; Errors: 0) (2.00 ms)
160+ Chrome 11.0.696.57 Mac OS: Run 1 tests (Passed: 1; Fails: 0; Errors 0) (2.00 ms)
161+
162+ Yay! The test passed!
163+
164+ # Experiments
165+
166+ * Add another binding to `index.html`. For example:
167+
168+ <p>Total number of phones: {{phones.length}}</p>
169+
170+ * Create a new model property in the controller and bind to it from the template. For example:
171+
172+ this.hello = "Hello, World!"
173+
174+ * Create a repeater that constructs a simple table:
175+
176+ <table>
177+ <tr><th>row number</th></tr>
178+ <tr ng:repeat="i in [0, 1, 2, 3, 4, 5, 6, 7]"><td>{{i}}</td></tr>
179+ </table>
180+
181+ Now, make the list 1-based by incrementing `i` by one in the binding:
147182
148- 2. Open a new browser tab or window, navigate to http://localhost:9876, and choose "strict
149- mode". At this point, you can leave this tab open and forget about it. JsTestDriver will
150- use it to execute our tests and report the results in the terminal.
183+ <table>
184+ <tr><th>row number</th></tr>
185+ <tr ng:repeat="i in [0, 1, 2, 3, 4, 5, 6, 7]"><td>{{i+1}}</td></tr>
186+ </table>
151187
152- 3. Execute the test by running `./scripts/test.sh`
188+ * Make the unit test fail by changing the `toBe(3)` statement to `toBe(4)`, and rerun the
189+ `./scripts/test.sh` script.
153190
154- You should see the following or similar output:
155191
156- Chrome: Runner reset.
157- .
158- Total 1 tests (Passed: 1; Fails: 0; Errors: 0) (2.00 ms)
159- Chrome 11.0.696.57 Mac OS: Run 1 tests (Passed: 1; Fails: 0; Errors 0) (2.00 ms)
192+ # Summary
160193
161- Yay! The test passed! Now, let's go to Step 3 to learn how to add full text search to the app.
194+ You now have a dynamic app that features separate model, view, and controller components, and
195+ you're testing as you go. Now, let's go to step 3 to learn how to add full text search to the app.
162196
163197
164198<table id="tutorial_nav">
0 commit comments