Skip to content

Commit d90cbe4

Browse files
committed
step-2 angular template with repeater
- Converted the static html list into dynamic one by: - creating PhoneListCtrl controller for the application - extracting the data from HTML into a the controller as an in-memory dataset - converting the static document into a template with the use of `[ngRepeat]` [directive] which iterates over the dataset with phones, clones the ngRepeat template for each instance and renders it into the view - Added a simple unit test to show off how to write tests and run them with JsTD (see README.md for instructions)
1 parent 7abe1a3 commit d90cbe4

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

app/index.html

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,14 @@
66
<link rel="stylesheet" href="css/app.css">
77
<link rel="stylesheet" href="css/bootstrap.css">
88
<script src="lib/angular/angular.js"></script>
9+
<script src="js/controllers.js"></script>
910
</head>
10-
<body>
11+
<body ng-controller="PhoneListCtrl">
1112

1213
<ul>
13-
<li>
14-
<span>Nexus S<span>
15-
<p>
16-
Fast just got faster with Nexus S.
17-
</p>
18-
</li>
19-
<li>
20-
<span>Motorola XOOM™ with Wi-Fi<span>
21-
<p>
22-
The Next, Next Generation tablet.
23-
</p>
14+
<li ng-repeat="phone in phones">
15+
{{phone.name}}
16+
<p>{{phone.snippet}}</p>
2417
</li>
2518
</ul>
2619

app/js/controllers.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
'use strict';
22

33
/* Controllers */
4+
5+
function PhoneListCtrl($scope) {
6+
$scope.phones = [
7+
{"name": "Nexus S",
8+
"snippet": "Fast just got faster with Nexus S."},
9+
{"name": "Motorola XOOM™ with Wi-Fi",
10+
"snippet": "The Next, Next Generation tablet."},
11+
{"name": "MOTOROLA XOOM™",
12+
"snippet": "The Next, Next Generation tablet."}
13+
];
14+
}

test/unit/controllersSpec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
'use strict';
22

33
/* jasmine specs for controllers go here */
4+
describe('PhoneCat controllers', function() {
45

5-
describe('controllers', function() {
6+
describe('PhoneListCtrl', function(){
67

8+
it('should create "phones" model with 3 phones', function() {
9+
var scope = {},
10+
ctrl = new PhoneListCtrl(scope);
11+
12+
expect(scope.phones.length).toBe(3);
13+
});
14+
});
715
});

0 commit comments

Comments
 (0)