0

I am using AngularJS' $resource directive to implement a REST interface on the client side. The server side's implementation works flawlessly. However, on the client side I am stuck. On the data side I have a materials model which holds an array of materials. Each material has an id property. The materials are displayed in a list with a delete button next to each one.

This is my JavaScript code for the deletion of a material:

var mainApp = angular.module('main', [ 'ngResource' ]);
mainApp.controller('materialController', function($scope, $resource) {
  var materialIO = $resource('/materials' + "/:id");
  $scope.del = function(material) {
        materialIO.remove({id:material.id}, {}, function(deletedId) {
            console.log(deletedId);
        });
    };
}

The server's response for a deletion request contains either the id (i.e. a number) of the deleted material or -1 if the material does not exist. However, AngularJS fills deletedId with a Resource object instead. This object contains a seemingly endless Resource-Promise chain: Chrome console with the logging information for deletedId

Bastian
  • 4,638
  • 6
  • 36
  • 55
  • but where did you set that `method: 'DELETE'` ? – Avraam Mavridis Nov 25 '14 at 13:49
  • @Avraam Nowhere. The [AngularJS documentation](https://docs.angularjs.org/api/ngResource/service/$resource) says that `'remove': {method:'DELETE'}` is a default action. So why specify it myself? – Bastian Nov 25 '14 at 14:00

0 Answers0