42 lines
903 B
JavaScript
42 lines
903 B
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
angular.module('app').controller('ListCtrl', Ctrl);
|
|
|
|
function Ctrl($http, modalService) {
|
|
var vm = this;
|
|
vm.tasks = [];
|
|
vm.newTitle = '';
|
|
|
|
vm.addTask = addTask;
|
|
vm.removeTask = removeTask;
|
|
|
|
init();
|
|
|
|
function init() {
|
|
$http.get('api/tasks').then(function (result) {
|
|
vm.tasks = result.data;
|
|
});
|
|
}
|
|
|
|
function addTask() {
|
|
var newTask = {
|
|
title: vm.newTitle,
|
|
added: new Date()
|
|
};
|
|
|
|
$http.post('api/tasks', newTask).then(init);
|
|
|
|
vm.newTitle = '';
|
|
}
|
|
|
|
function removeTask(id) {
|
|
modalService.confirm()
|
|
.then(function () {
|
|
return $http.delete('api/tasks/' + id);
|
|
}).then(init);
|
|
}
|
|
}
|
|
})();
|
|
|