Skip to content

Commit

Permalink
AngularJS Delete
Browse files Browse the repository at this point in the history
  • Loading branch information
amejiarosario committed Oct 3, 2014
1 parent b639444 commit b9ff3a8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<input type="checkbox" ng-model="todo.completed" ng-change="update($index)">
<a ng-show="!editing[$index]" href="#/{{todo._id}}">{{todo.name}}</a>
<button ng-show="!editing[$index]" ng-click="edit($index)">edit</button>
<button ng-show="!editing[$index]" ng-click="remove($index)">remove</button>

<input ng-show="editing[$index]" type="text" ng-model="todo.name">
<button ng-show="editing[$index]" ng-click="update($index)">update</button>
Expand All @@ -37,6 +38,7 @@
note: <textarea ng-model="todo.note"></textarea><br><br>

<button ng-click="update()">update</button>
<button ng-click="remove()">remove</button>
<a href="/">Cancel</a>
</script>

Expand Down Expand Up @@ -85,6 +87,13 @@
$scope.todos[index] = angular.copy($scope.editing[index]);
$scope.editing[index] = false;
}
$scope.remove = function(index){
var todo = $scope.todos[index];
Todos.remove({id: todo._id}, function(){
$scope.todos.splice(index, 1);
});
}
}])
.controller('TodoDetailCtrl', ['$scope', '$routeParams', 'Todos', '$location', function ($scope, $routeParams, Todos, $location) {
Expand All @@ -95,6 +104,12 @@
$location.url('/');
});
}
$scope.remove = function(){
Todos.remove({id: $scope.todo._id}, function(){
$location.url('/');
});
}
}])
//---------------
Expand Down

1 comment on commit b9ff3a8

@yenerorer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too good to be true, thank you.. ;)

Please sign in to comment.