簡體   English   中英

MEAN堆棧刪除

[英]MEAN stack delete

嘗試將刪除按鈕添加到我的帖子列表中,這將從數據庫中刪除該條目,但僅在單擊該按鈕時才會為空。

我的$ scope

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

鏈接到此功能:

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.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);
            });
        });
    });

紐扣

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

我的console.log寫入null,並且沒有任何內容被刪除。 非常感謝我能得到的所有幫助,因為我很困!

您將擁有:

_id : req.params.post

代替:

_id : req.params.id

因為您在路線中具有:post參數:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM