Reputation: 413
I'm trying to delete a record from MongoDB by using Angular on the FrontEnd, but somehow I can't get it to work.
This is my Delete request in Express:
router.get('/ideas/:id', function(req, res){
ideas_data.remove({_id: req.params.id}, function(err){
if(err) res.json(err);
else res.redirect('/');
});
});
And this is the http function in Angular:
$scope.deleteRec = function(id){
$http.delete('/ideas/:id', {_id : id})
.then(function successCallback(response) {
console.log(response);
});
};
And this is the function call on click in HTML
<a href="/{{title}}/{{x._id}}" ng-click="deleteRec(x._id)">
<div class="icon cross">
<img src="/images/icons/cross.svg"/>
</div>
</a>
Upvotes: 0
Views: 131
Reputation: 10071
You are calling delete method from angular and server you have written get.
router.delete('/ideas/:id', function (req, res) {
ideas_data.remove({
_id: req.params.id
}, function (err) {
if (err) res.json(err);
else res.redirect('/');
});
});
Upvotes: 1