var app = angular.module('todoList',[]);
app.controller('TodoController', ['$scope', '$http', function($scope, $http) {
$scope.todoslist = list;
$scope.addTodo = function() {
$scope.todoslist.push({
"id": ""+$scope.todoslist.length + 1,
"description": ""+$scope.newTodo,
"completed": "false"
});
};
$scope.deleteTodo = function (todo) {
if (''+todo.completed === "true"){
$scope.todoslist.splice($scope.todoslist.indexOf(todo), 1);
}
};
$scope.markAll = function (completed) {
$scope.todoslist.forEach(function (todo) {
todo.completed = completed;
});
};
}]);
var list = [
{"id":"1","description":"text 1","completed":"false"},
{"id":"2","description":"text 2","completed":"false"},
{"id":"3","description":"text 3","completed":"false"},
{"id":"4","description":"text 4","completed":"false"},
{"id":"5","description":"text 5","completed":"false"}
];
})(); |