2016-12-06 4 views
1

Ich habe einen Dienst mit ngResource, mit dem ich auf Kommentare für bestimmte Nachrichtenbeiträge in meiner Webanwendung zugreifen kann.Angeben von URL-Parametern in ngResource

Mein Problem ist, dass, wenn ich für eine bestimmte Nachrichten Post abzufragen Kommentare will, wie diese article.comments = commentService.query() Die get-Anfrage an /api/news/comments gemacht wird, insteaf von /api/news/:id/comments. Wie kann ich die ID angeben, so dass die Get-Anfrage an die richtige URL (/api/news/:id/comments) gesendet wird?

commentService

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

Mehtod für Kommentare zu holen ng Sie auf

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

Antwort

2

Ich löste es wie dieses

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