Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TodoController-1.js
myApp.controller('TodoController', [ '$scope', 'TodoService', function ($scope, TodoService) {
$scope.newTodo = {};
$scope.loadTodos = function(){
TodoService.loadTodos().
success(function(data, status, headers, config) {
$scope.todos = data;
})
.error(function(data, status, headers, config) {
alert('Error loading Todos');
});
};
$scope.addTodo = function(){
TodoService.createTodo($scope.newTodo).
success(function(data, status, headers, config) {
$scope.newTodo = {};
$scope.loadTodos();
})
.error(function(data, status, headers, config) {
alert('Error saving Todo');
});
};
$scope.deleteTodo = function(todo){
TodoService.deleteTodo(todo.id).
success(function(data, status, headers, config) {
$scope.loadTodos();
})
.error(function(data, status, headers, config) {
alert('Error deleting Todo');
});
};
$scope.loadTodos();
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.