无法读取未定义的 ngResource 的 属性 '$remove'

cannot read property '$remove' of undefined ngResource

我的服务器中有一个工作 api,我的 CRUD 模块工作正常,我可以在我的服务器中获取,post,放置,删除

我的 angular 控制器中也有 CRUD 模块,除了删除功能外,它都工作正常

我正在使用 ngResource $save, $update,$remove 来处理客户端中的数据一直到服务器

$save 和 $update 工作正常,但是 $remove returns 给我一个错误:"cannot read property $remove of undefined"

这是我的控制器

$scope.findOne = function () {
    $scope.post = Posts.get({
        postId: $routeParams.postId
    });
};

$scope.update = function () {
    $scope.post.$update(function () {
        $location.path('posts/' + $scope.post._id);
    }, function (errorResponse) {
        $scope.error = errorResponse.data.message;
    });
};

$scope.delete = function (post) {
    if (post) {
        post.$remove(function () {
            for (var i in $scope.posts) {
                if ($scope.posts[i] === post) {
                    $scope.posts.splice(i, 1);
                }
            }
        });
    }
    else {
        $scope.posts.$remove(function () {
            $location.path('posts');
        });
    }
};

我的服务

angular.module('posts').factory('Posts', ['$resource',
    function ($resource) {
        return $resource('posts/:postId', {
            postId: '@_id' 
        }, {
            update: {
                method: 'PUT'
            }
        });
    }
]);

奇怪的是,更新有效,但删除无效

是不是因为我在delete方法中有参数?

这是我的看法

<div data-ng-controller="PostsCtrl">
<section data-ng-init="findOne()">
    <div data-ng-show="authentication.user._id === post.author._id">
        <a href="/#!/posts/{{post._id}}/edit">Edit</a>
        <a href="#" data-ng-click="delete()">delete</a>
    </div>
</section>
</div>

为什么我不能删除 post 而它 returns 未定义? ngResource 中不再使用 $remove 了吗?

ngResource 中有哪些方法可用?

一样使用Posts.remove$scope.post.$remove
$scope.post.$remove(successCallBack,errorCallBack) //careful the item ($scope.post) will be removed.

Posts.remove({},{postId: 'your post id'})

$scope.delete方法的参数不包含$resource

的引用