(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 = ""; }; } }]); })();