0

I have set up the following resource, function and cell template:

var Exam = $resource('/api/Tests', {}, {
    saveData: { method: 'PUT' }
});
$scope.delete = function (row) {
    row.entity.$delete(row.examId);
}
$scope.updateEntity = function (column, row) {
    console.log(row.entity);
    console.log(column.field);
    row.entity.$saveData();
}

{ field: '', cellTemplate: '<button ng-click="delete(row)">Delete</button>' }

However I find that it is only sending:

   DELETE /api/Tests HTTP/1.1

Is there a way I can change the resource so that if the row testId is equal to one then it correctly sends

   DELETE /api/Tests/1

Note that I already tried the following but it still sends the same URL to my server:

   row.entity.$delete(row.entity.testId)

One more thing. My updateEntity works and sends a put along with a json of the row

1 Answers1

2

You can either change the url in for your resource like this:

var Exam = $resource('api/Tests/:id, {id:'default value here'});

Exam.$delete({id:1});

Or redefine the delete action:

var Exam = $resource('api/Tests, {}, {
    $delete: {
        method: 'DELETE',
        params: {id: 'some value here'}
    }
});

Have a look at this similar question: https://stackoverflow.com/a/13275194/1036025

Community
  • 1
  • 1
jpmorin
  • 6,008
  • 2
  • 28
  • 39
  • Thanks this looks good but the value of 'some value here' would be different. If i redefine the delete action then how could I change the calling function to set the value? –  Apr 11 '13 at 16:27
  • I added a link to a similar question that may help you! – jpmorin Apr 11 '13 at 16:28
  • The parameters sent when calling the $delete function will override the values of those specified (ie: Exam.$delete({id:1})). I think that the first option is sufficient. – jpmorin Apr 11 '13 at 16:30