-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo.js
45 lines (35 loc) · 956 Bytes
/
todo.js
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
(function() {
var appDependencies = [];
var app = angular.module('todoapp', appDependencies);
app.controller("TodoCtrl", TodoCtrl);
app.directive("todoLi", function() {
return {
restrict: 'E', // E for element (tag), A for attribute
templateUrl: 'todo-li.html'
};
});
})();
function TodoCtrl($scope) {
$scope.todos = [
{text:"Learn AngularJs", done:false},
{text:"Complete Todo-App", done:false}
];
$scope.totalTodos = function() {
return $scope.todos.length;
};
$scope.addTodo = function() {
$scope.todos.push({text: $scope.newTodoText, done:false});
$scope.newTodoText = "";
}
var todosNotDone = function () {
return _.filter($scope.todos, function(todo) {
return !todo.done;
});
}
$scope.clearCompleted= function() {
$scope.todos = todosNotDone();
}
$scope.numCompletedTodos = function() {
return $scope.todos.length - todosNotDone().length;
}
}