2016-12-06 3 views
1

Webアプリケーション内の特定のニュース投稿のコメントにアクセスするために使用するngResourceを使用するサービスがあります。ngResourceにURLパラメータを指定します。

私の問題は、私はこのarticle.comments = commentService.query() のように、特定のニュース記事のコメントを照会したい場合、GET要求が/api/news/:id/commentsのinsteaf、/api/news/commentsに行われていることです。取得リクエストが正しいURL(/api/news/:id/comments)に送信されるように、:idを指定するにはどうすればよいですか?

commentService

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

NGクリック

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

答えて

2

にコメントをフェッチするmehtod私はこの

$scope.getComments = function(article) { 
    return commentService.query({id:article._id}) 
} 
のようにそれを解決しました
関連する問題