angularjs - MEAN stack delete -


trying add delete button list of posts, delete entry database, gets null when clicking button.

my $scope

$scope.remove = function(post) {   posts.remove(post); } 

links function:

o.remove = function(post) {     $http({ url: '/posts/' + post._id,              method: 'delete'                     }).then(function(res) {         // deleted         console.log(data);         // update list         $http.get("/posts")             .success(function(data, status, headers, config) {               console.log(data);                         });     }, function(error) {         console.log(error);     });   }; 

router:

router.delete('/posts/:post', function(req, res, next) {         post.remove({             _id : req.params.id         }, function(err, post) {             if (err)                 res.send(err);              post.find(function(err, post) {                 if (err)                     res.send(err)                 res.json(post);             });         });     }); 

button

    <span ng-click="remove(post)">       delete     </span> 

my console.log writes null, , nothing gets deleted. appreciate can get, stuck!

you shall have:

_id : req.params.post 

instead of:

_id : req.params.id 

because have :post param in route:

router.delete('/posts/:post', function(req, res, next) { 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -