Skip to content

Commit a22faf7

Browse files
committed
Add examples from Brad's chapters 1, 2 and 6
1 parent 49b80ac commit a22faf7

File tree

372 files changed

+41291
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

372 files changed

+41291
-0
lines changed

chapter1/HelloDynamic.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html ng-app>
2+
<head>
3+
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
4+
<script src="controllers.js"></script>
5+
</head>
6+
<body>
7+
<div ng-controller='HelloController'>
8+
<input ng-model='greeting.text'>
9+
<p>{{greeting.text}}, World</p>
10+
</div>
11+
</body>
12+
</html>

chapter1/controllers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function HelloController($scope) {
2+
$scope.greeting = { text: 'Hello' };
3+
}

chapter1/hello-world-js.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<html>
2+
<head><title>Hello, World in JavaScript</title></head>
3+
<body>
4+
<p id="greeting"></p>
5+
<script type="text/javascript">
6+
var isIE = document.attachEvent;
7+
var addListener = isIE
8+
? function(e, t, fn) {e.attachEvent('on' + t, fn);}
9+
: function(e, t, fn) {e.addEventListener(t, fn, false);};
10+
11+
addListener(window, 'load', function() {
12+
var greeting = document.getElementById('greeting');
13+
if (isIE) {
14+
greeting.innerText = 'Hello, World';
15+
} else {
16+
greeting.textContent = 'Hello, World';
17+
}
18+
});
19+
</script>
20+
</body>
21+
</html>

chapter1/order-form.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!doctype html>
2+
<html lang='en' ng-app>
3+
<head>
4+
<title>Shopping Cart</title>
5+
</head>
6+
7+
<body ng-controller="CartCtrl">
8+
<h1>Your Shopping Cart</h1>
9+
10+
<div ng-repeat="item in items">
11+
<span>{{item.title}}</span>
12+
<input ng-model="item.quantity">
13+
<span>{{item.price | currency}}</span>
14+
<span>{{item.price * item.quantity | currency}}</span>
15+
<button ng-click="remove($index)">Remove</button>
16+
</div>
17+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
18+
<script>
19+
function CartCtrl($scope) {
20+
$scope.items = [
21+
{title: 'Paint pots', quantity: 8, price: 3.95},
22+
{title: 'Polka dots', quantity: 17, price: 12.95},
23+
{title: 'Pebbles', quantity: 5, price: 6.95}
24+
];
25+
26+
$scope.remove = function(index) {
27+
$scope.items.splice(index, 1);
28+
}
29+
}
30+
</script>
31+
</body>
32+
</html>

chapter2/1.dataBinding.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<html ng-app=>
2+
<body ng-controller="TextController">
3+
<p>{{someText.message}}</p>
4+
5+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
6+
7+
<script>
8+
function TextController($scope) {
9+
var someText = {};
10+
someText.message = 'You have started your journey.';
11+
$scope.someText = someText;
12+
}
13+
</script>
14+
</body>
15+
</html>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<html ng-app='myApp'>
2+
<body ng-controller="TextController">
3+
<p>{{someText.message}}</p>
4+
5+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
6+
7+
<script>
8+
var myAppModule = angular.module('myApp', []);
9+
10+
myAppModule.controller('TextController',
11+
function TextController($scope) {
12+
var someText = {};
13+
someText.message = 'You have started your journey.';
14+
$scope.someText = someText;
15+
});
16+
</script>
17+
</body>
18+
</html>

chapter2/aMail/angular.min.js

Lines changed: 157 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chapter2/aMail/controllers.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
var aMailServices = angular.module('AMail', []);
2+
3+
function emailRouteConfig($routeProvider) {
4+
$routeProvider.
5+
when('/', {
6+
controller: ListController,
7+
templateUrl: 'list.html'
8+
}).
9+
when('/view/:id', {
10+
controller: DetailController,
11+
templateUrl: 'detail.html'
12+
}).
13+
otherwise({
14+
redirectTo: '/'
15+
});
16+
}
17+
18+
aMailServices.config(emailRouteConfig);
19+
20+
messages = [{
21+
id: 0,
22+
sender: '[email protected]',
23+
subject: 'Hi there, old friend',
24+
date: 'Dec 7, 2013 12:32:00',
25+
recipients: ['[email protected]'],
26+
message: 'Hey, we should get together for lunch sometime and catch up. There are many things we should collaborate on this year.'
27+
}, {
28+
id: 1,
29+
sender: '[email protected]',
30+
subject: 'Where did you leave my laptop?',
31+
date: 'Dec 7, 2013 8:15:12',
32+
recipients: ['[email protected]'],
33+
message: 'I thought you were going to put it in my desk drawer. But it does not seem to be there.'
34+
}, {
35+
id: 2,
36+
sender: '[email protected]',
37+
subject: 'Lost python',
38+
date: 'Dec 6, 2013 20:35:02',
39+
recipients: ['[email protected]'],
40+
message: "Nobody panic, but my pet python is missing from her cage. She doesn't move too fast, so just call me if you see her."
41+
}, ];
42+
43+
function ListController($scope) {
44+
$scope.messages = messages;
45+
}
46+
47+
function DetailController($scope, $routeParams) {
48+
$scope.message = messages[$routeParams.id];
49+
}

chapter2/aMail/detail.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div><strong>Subject:</strong> {{message.subject}}</div>
2+
<div><strong>Sender:</strong> {{message.sender}}</div>
3+
<div><strong>Date:</strong> {{message.date}}</div>
4+
<div><strong>To:</strong><span ng-repeat='recipient in message.recipients'>{{recipient}} </span>
5+
<div>{{message.message}}</div>
6+
<a href='#/'>Back to message list</a>

chapter2/aMail/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html ng-app="AMail">
3+
<head>
4+
<!--script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script-->
5+
<script src='angular.min.js'></script>
6+
<script src='controllers.js'></script>
7+
</head>
8+
<body>
9+
<h1>A-Mail</h1>
10+
<div ng-view></div>
11+
</body>
12+
</html>

chapter2/aMail/list.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<table>
2+
<tr>
3+
<td><strong>Sender</strong></td>
4+
<td><strong>Subject</strong></td>
5+
<td><strong>Date</strong></td>
6+
</tr>
7+
<tr ng-repeat='message in messages'>
8+
<td>{{message.sender}}</td>
9+
<td><a href='#/view/{{message.id}}'>{{message.subject}}</td>
10+
<td>{{message.date}}</td>
11+
</tr>
12+
</table>

0 commit comments

Comments
 (0)