From 0a604bdb90e9dff9399bae0fb4941fe46cc7e9f9 Mon Sep 17 00:00:00 2001 From: Kenneth R. Culp Date: Tue, 26 Apr 2011 09:54:08 -0700 Subject: Tutorial files for your perusal. --- docs/tutorial.step_4.ngdoc | 114 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100755 docs/tutorial.step_4.ngdoc (limited to 'docs/tutorial.step_4.ngdoc') diff --git a/docs/tutorial.step_4.ngdoc b/docs/tutorial.step_4.ngdoc new file mode 100755 index 00000000..260ad38f --- /dev/null +++ b/docs/tutorial.step_4.ngdoc @@ -0,0 +1,114 @@ +@workInProgress +@ngdoc overview +@name Tutorial: Step 4 +@description +
| {@link tutorial.step_3 Previous} | +{@link http://angular.github.com/angular-phonecat/step-4/app Example} | +{@link tutorial Tutorial Home} | +{@link +https://github.com/angular/angular-phonecat/commit/b56c91f453114347f0cb25e70b1c4fa4f1421763 Code +Diff} | +{@link tutorial.step_5 Next} | +
+... +
{{phone.snippet}}
+
+/* App Controllers */
+
+function PhoneListCtrl() {
+ this.phones = [{"name": "Nexus S",
+ "snippet": "Fast just got faster with Nexus S.",
+ "age": 0},
+ {"name": "Motorola XOOM™ with Wi-Fi",
+ "snippet": "The Next, Next Generation tablet.",
+ "age": 1},
+ {"name": "MOTOROLA XOOM™",
+ "snippet": "The Next, Next Generation tablet.",
+ "age": 2}];
+
+ this.orderProp = 'age';
+}
+
+
+__`test/unit/controllerSpec.js`:__
+
+/* jasmine specs for controllers go here */
+describe('PhoneCat controllers', function() {
+
+ describe('PhoneListCtrl', function(){
+ var scope, $browser, ctrl;
+
+ beforeEach(function() {
+ ctrl = new PhoneListCtrl();
+ });
+
+
+ it('should create "phones" model with 3 phones', function() {
+ expect(ctrl.phones.length).toBe(3);
+ });
+
+
+ it('should set the default value of orderProp model', function() {
+ expect(ctrl.orderProp).toBe('age');
+ });
+ });
+});
+
+
+## Discussion:
+
+To provide dynamic ordering, we employ another one of angular's "array type augmenters" and let
+the data binding do the rest of the work for us:
+
+* Like {@link angular.Array.filter $filter}, {@link angular.Array.orderBy $orderBy} is a built-in
+method available on array objects in angular expressions. In our UI template, we set up a select
+box that lets the user set the `orderProp` model variable to one of the string constants: `age` or
+`name`.
+
+* In our controller, we added a line to set the default value of `orderProp` to `age`.
+
+* Our unit test now verifies that our default ordering property is set.
+
+* Once again we added a little more CSS to improve the View.
+
+| {@link tutorial.step_3 Previous} | +{@link http://angular.github.com/angular-phonecat/step-4/app Example} | +{@link tutorial Tutorial Home} | +{@link +https://github.com/angular/angular-phonecat/commit/b56c91f453114347f0cb25e70b1c4fa4f1421763 Code +Diff} | +{@link tutorial.step_5 Next} | +