2016-12-06 54 views
1

我有一個使用ngResource的服務,用於訪問我的webapp中特定新聞帖子的評論。在ngResource中指定url參數

我的問題是,當我想查詢註釋特定消息後,這樣article.comments = commentService.query() 的GET請求來/api/news/comments製成,insteaf的/api/news/:id/comments。我如何指定:id以便將獲取請求發送到正確的url(/api/news/:id/comments)?

commentService

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

mehtod用於獲取有關意見NG單擊

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

回答

2

我解決它像這樣

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