angularjs - How can I use $resource to send a HTTP DELETE request to my server? -


i have following code:

var entityresource = $resource('/api/' + $scope.entitytype + '/');  entityresource.delete(entityid,    function (result) {       $scope.remove($scope.grid.data, idcolumn, entityid);    }, function (result) {       alert("error: " + result);    }) 

when code executes following message:

delete http://127.0.0.1:81/api/subject 404 (not found)   {"message":"no http resource found matches request uri 'http://127.0.0.1:81/api/subject'.","messagedetail 

how can make $resource sends delete /api/subject/123 right seems ignore value of entityid

here tried far after advice:

    var entityresource = $resource('/api/:entitytype/:entityid',            { entitytype: '@type', entityid: '@id' });     entityresource.delete({ type: $scope.entitytype, id: entityid },          function (result) {             $scope.remove($scope.grid.data, idcolumn, entityid);             $scope.remove($scope.grid.backup, idcolumn, entityid);             $scope.close();         }, function (result) {             alert("error: " + result);         }) 

unfortunately give me: delete /api?id=12&type=subject http/1.1

you need set entity id in template:

var entityresource = $resource('/api/:entitytype/:entityid',                                 {type:'@entitytype', id: '@entityid'}); 

then when call it, pass in parameters:

entityresource.delete({type: $scope.entitytype, id: entityid}, success, failure); 

or

var entity = new entityresource({type: $scope.entitytype, id: entityid}); entity.$delete(success, failure); 

assuming success , failure loke this:

var success = function (result) {     $scope.remove($scope.grid.data, idcolumn, entityid); };  var failure = function (result) {     alert("error: " + result); }; 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -