-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03-todo-list-ng-repeat.html
94 lines (77 loc) · 2.1 KB
/
03-todo-list-ng-repeat.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<html lang="en" data-ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>03-todo-list-ng-repeat</title>
<!--App Dependencies-->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<style>
.done-true {
text-decoration: line-through;
color: grey;
}
</style>
</head>
<body>
<!--App view-->
<div data-ng-controller="AppCtrl">
<h1>{{title}}</h1>
<span>{{remaining()}} of {{length}} remaining</span>
[ <a href="" data-ng-click="archive()">Archive</a> ]
<ul class="unstyled">
<li data-ng-repeat="todo in todos">
<label class="checkbox">
<input type="checkbox" data-ng-model="todo.done">
<span class="done-{{todo.done}}">{{todo.text}}</span>
</label>
</li>
</ul>
<form data-ng-submit="addTodo()">
<input type="text" data-ng-model="todoText" size="30"
placeholder="Add new todo here">
<input type="submit" value="add">
</form>
</div>
<!--App scripts-->
<script>
angular
.module('myApp', [])
.controller('AppCtrl', AppCtrl);
AppCtrl.$inject = ['$scope'];
function AppCtrl($scope) {
//vm locals
$scope.title = "Todo";
$scope.todos = [
{text: 'learn angular', done: true},
{text: 'build an angular app', done: false}
];
//vm functions
$scope.addTodo = addTodo;
$scope.remaining = remaining;
$scope.archive = archive;
//Add new todo.
function addTodo() {
$scope.todos.push({text: $scope.todoText, done: false});
$scope.todoText = '';
}
//Remaining todos.
function remaining() {
var count = 0;
angular.forEach($scope.todos, function (todo) {
count += todo.done ? 0 : 1;
});
return count;
}
//Remove completed todos.
function archive() {
var oldTodos = $scope.todos;
$scope.todos = [];
angular.forEach(oldTodos, function (todo) {
if (!todo.done) $scope.todos.push(todo);
});
}
}
</script>
<!--check out other one page boilerplates over here > https://github.com/shahzadns/one-page-boilerplates -->
</body>
</html>