簡體   English   中英

RESTAngular-刪除,無法正常工作

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

如果我沒有誤解RESTful服務以刪除記錄,則需要執行以下操作:

Delete a product: DELETE /api/product/id參考

但是在RESTAngular中,例如

product.remove();

/api/product發出了DELETE請求,請求主體中的整個產品對象也是如此。 這不是我想要的!

這是我的代碼:

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

獲得一個產品

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

刪除產品

$scope.product.remove();

我想在執行product.remove()時將DELETE請求發送到/ myAPI / product / id。 我怎樣才能做到這一點?

// 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