在 ngResource 中指定 url 参数

Specify url parameters in ngResource

我有一个使用 ngResource 的服务,我用它来访问我的网络应用程序中特定新闻 posts 的评论。

我的问题是,当我想查询特定新闻的评论时 post,像这样 article.comments = commentService.query()/api/news/comments 发出获取请求,而不是 /api/news/:id/comments。如何指定 :id 以便将 get 请求发送到右侧 url(/api/news/:id/comments)?

评论服务

   .factory('commentService', function($resource){
        return $resource('/api/news/:id/comments/:comment', {id: '@news', comment: '@comment'}, {
            update: {
                method: 'PUT'
            }
        }, {
            stripTrailingSlashes: false
        }
    )})

在 ng-click 上获取评论的方法

$scope.getComments = function(article) {
    article.comments = commentService.query()
}

我是这样解决的

$scope.getComments = function(article) {
    return commentService.query({id:article._id})
}