What is a clean way to send a body with DELETE request?

后端 未结 3 1452
终归单人心
终归单人心 2020-12-08 20:26

I need to send a request body with my DELETE requests using $resource

The only way I could see to do this was to change:

https://github.com/angular/angular.j

相关标签:
3条回答
  • 2020-12-08 20:42

    You can inject the $http (http://docs.angularjs.org/api/ng.%24http#Usage) component into one of one of your controllers and by using it as follows :

    $http({method: 'DELETE', url: 'www.url.com', headers: {'X-MY-HEADER': 'MY_VALUE'}});
    

    I hope this what you expected.

    0 讨论(0)
  • 2020-12-08 20:45

    You should be able to call 'remove' on your resource as explained in the documentation https://docs.angularjs.org/api/ngResource/service/$resource

    0 讨论(0)
  • 2020-12-08 20:59

    This works.

    $scope.delete = function(object) {
        $http({
            url: 'domain/resource',
            method: 'DELETE',
            data: {
                id: object.id
            },
            headers: {
                "Content-Type": "application/json;charset=utf-8"
            }
        }).then(function(res) {
            console.log(res.data);
        }, function(error) {
            console.log(error);
        });
    };
    
    0 讨论(0)
提交回复
热议问题