controller.js
1.16 KB
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
(function() {
var app = angular.module('todoapp', []);
app.controller('TodoCtrl', ['$scope', '$http', function($scope, $http) {
//console.log("Hello World from controller");
$http.get('/todolist').success(function(response) {
//console.log("I got the data I requested");
$scope.todolist = response;
});
$scope.task = {
taskname: "",
Done: false,
details: ""
}
$scope.addTask = function() {
//console.log($scope.todo);
$http.post('/todolist', $scope.task).success(function(response){
$http.get('/todolist').success(function(response) {
$scope.todolist = response;
});
console.log(response);
$scope.task = {
taskname: "",
Done: false,
details: ""
}
});
};
$scope.updateTask = function(task) {
$http.put('/todolist/'+task._id,task).success(function(response) {
});
};
$scope.deleteTask = function(id) {
var x=confirm("Are you sure?")
if(x==true){
$http.delete('/todolist/' + id).success(function(response) {
console.log(response);
});
$http.get('/todolist').success(function(response) {
$scope.todolist = response;
});
$scope.todo = "";
};
}
}]);
})();