简体   繁体   English

RESTAngular-删除,无法正常工作

[英]RESTAngular - DELETE, not working as it should

If i am not mistaken in RESTful services in order to remove a record you need to do this: 如果我没有误解RESTful服务以删除记录,则需要执行以下操作:

Delete a product: DELETE /api/product/id ( reference ) Delete a product: DELETE /api/product/id参考

But in RESTAngular when i do for example 但是在RESTAngular中,例如

product.remove();

A DELETE request is made to /api/product whith the whole product object in the Requests Body. /api/product发出了DELETE请求,请求主体中的整个产品对象也是如此。 This is not what i want! 这不是我想要的!

Here is my code: 这是我的代码:

myApp.factory('RESTService', [ 'Restangular', function (Restangular) {
    var restAngular = Restangular.withConfig(function (Configurer) {
        Configurer.setBaseUrl('/myAPI/');
    });
    var service = {};
    service.Product= restAngular.service('product');
    return service;
}]);

GET one Product 获得一个产品

RESTService.Product.one(id).get().then(function (response) {
    $scope.product= response;
})

DELETE the Product 删除产品

$scope.product.remove();

I want when i do product.remove() to send a DELETE Request to /myAPI/product/id. 我想在执行product.remove()时将DELETE请求发送到/ myAPI / product / id。 How can i do that? 我怎样才能做到这一点?

// DELETE /accounts/123/buildings/456
Restangular.one("accounts", 123).one("buildings", 456).remove();

您可以像这样使用RESTFul($http)服务删除记录

$http.delete('/myAPI/product' + id, {params: {id: id}});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM