i399exng1/app/list.ctrl.js

42 lines
903 B
JavaScript
Raw Normal View History

2017-03-13 12:29:29 +02:00
(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);
}
}
})();