I'm making CRUD and if I want to send some data to my backend (node.js) then I receive an error: angular.js:10765 POST http://localhost:1234/shop/removeProduct/574bf938b16158b40f9c87bc 400 (Bad Request)
script:
$scope.removeProduct = function (partnerId, productId) { $http.post("/campaign/removeProduct/" + partnerId, productId); } The solution is just simply pack this parameter (productId) in an object like this:
$scope.removeProduct = function (partnerId, productId) { $scope.productData = {productId: productId}; $http.post("/campaign/removeProduct/" + partnerId, $scope.productData); } But why I have to do this like this? By the way, is this correct or should I do it in a different way?
@EDIT One more thing, how should i refresh data after I added/removed any object? Is this correct?
$scope.addPartner = function(data) { $http({method: 'POST', url: addPartner, data}) .then(function(response) { console.log(response); }); $scope.loadPartnersData(); window.alert("Partner added!"); }; $scope.loadPartnersData = function () { $http.get("/campaign/partner-list").then(function(result) { $scope.partnerList = result.data.partnerList; }); }; backend:
router.get('/partner-list', function (req, res) { Partner.find({}, function (err, partnerList) { if (err) throw err; res.json({ partnerList: partnerList }); }); });
DELETEverb w/o payload to perform delete?