Skip to content

Instantly share code, notes, and snippets.

@sivaprasadreddy
Created September 4, 2014 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivaprasadreddy/093de52472a2295ee408 to your computer and use it in GitHub Desktop.
Save sivaprasadreddy/093de52472a2295ee408 to your computer and use it in GitHub Desktop.
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