Why can't I pass parameter when http.delete in AngularJs?

I have a function to call http.delete and pass the parameter flag:

function softDeleteDatasource(datasourceId,flag) { var url = baseUrl + datasourceId; return $http.delete(url, {'currentFieldSetFlag':flag}); } 

Then I guess I can get req.body with the following code. However, I always get undefined in console.log . I used the exact same code in http.post and it works great when passing a parameter.

 var bodyParser = require('body-parser'); var jsonParser = bodyParser.json(); router.delete('/:datasourceId', jsonParser, function(req, res) { console.log(req.body.currentFieldSetFlag); } 

I am confused why the same code cannot pass the parameter to http.delete ? Does anyone know how to pass it?

+5
source share
1 answer

The HTTP specification allows bodies to DELETE, but some clients do not send them, and some proxies / servers will deprive / ignore them, if any. This should work to pass it as a querystring parameter:

 return $http.delete(url, {params: {'currentFieldSetFlag':flag}}); 
+4
source

All Articles