(function () { 'use strict'; angular.module('app').controller('ListCtrl', Ctrl); function Ctrl($http, modalService) { var vm = this; vm.items = [{ title: "hello", done: false }]; vm.newItem = ''; vm.addNew = addNew; vm.removeItem = removeItem; pullItems(); function pullItems() { $http.get('api/tasks').then(function(resp) { vm.items = resp.data; }); }; function removeItem(id) { modalService.confirm() .then(function() { return $http.delete('api/tasks/'+id); }).then(pullItems); } function addNew () { var item = {title:this.newItem, done:false}; $http.post('api/tasks', item).then(pullItems); //this.items.push(item); vm.newItem = ''; } } })();