Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
hello-ang-controller.js
angular.module('myApp')
.controller('TodoController', [ '$scope', '$http', function ($scope, $http) {
$scope.newTodo = {};
$scope.loadTodos = function(){
$http.get('todos')
.success(function(data, status, headers, config) {
$scope.todos = data;
})
.error(function(data, status, headers, config) {
alert('Error loading Todos');
});
};
$scope.addTodo = function(){
$http.post('todos',$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){
$http.delete('todos/'+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.