javascript - Not able to pass object with AngularJS to web backend -
title says all. i'm new i'm sure must simple mistake. here's controller
$scope.removeproduct = function(product){ console.log(product._id); var indata = new object(); indata._id = product._id; console.log(indata); $http({ url:"/api/deleteprod/", indata, method: "post" }).then(function () { console.log("got here"); var index = $scope.vehicles.indexof(product); $scope.vehicles.splice(index, 1); }) };
and here's server side.
module.exports = function(app, mongoose, config) { app.post('/api/deleteprod', function(req, res){ console.log("in app post",req); var mongoclient = mongodb.mongoclient; var url='mongodb://localhost:27017/seedsdev'; }); };
obviously want pass _id server can work it, when output req it's 50 pages long , has none of info wanted. before it's passed object can seen fine fia console.log.
what's rookie mistake i'm making?
when calling $http
, pass post
data data
property. you're passing indata
property. change this:
$http({ url:"/api/deleteprod/", data: indata, method: "post" }).then(...)
update:
on server side, you'll need make sure have json parsing middleware, body-parser
:
app.use(require('body-parser').json())
once parsing body using body-parser
, you'll have req.body
property parsed json.
Comments
Post a Comment