Permalink
Browse files

AngularJS Read with

1 parent 0221aeb commit 2aff6fe004bf7f7b2cd1b91d53e6958c3b158a20 @amejiarosario committed Oct 3, 2014
Showing with 7 additions and 9 deletions.
  1. +7 −9 views/index.ejs
View
@@ -12,6 +12,7 @@
<!-- Libraries -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.min.js"></script>
+ <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-resource.min.js"></script>
<!-- Template -->
<script type="text/ng-template" id="/todos.html">
@@ -31,27 +32,24 @@
</script>
<script>
- angular.module('app', ['ngRoute'])
+ angular.module('app', ['ngRoute', 'ngResource'])
//---------------
// Services
//---------------
- .factory('Todos', ['$http', function($http){
- return $http.get('/todos');
+ .factory('Todos', ['$resource', function($resource){
+ return $resource('/todos/:id', null, {
+ 'update': { method:'PUT' }
+ });
}])
//---------------
// Controllers
//---------------
.controller('TodoController', ['$scope', 'Todos', function ($scope, Todos) {
- Todos.success(function(data){
- $scope.todos = data;
- }).error(function(data, status){
- console.log(data, status);
- $scope.todos = [];
- });
+ $scope.todos = Todos.query();
}])
.controller('TodoDetailCtrl', ['$scope', '$routeParams', 'Todos', function ($scope, $routeParams, Todos) {

0 comments on commit 2aff6fe

Please sign in to comment.