My current setup involves utilizing ngResource in my service to retrieve comments for specific news posts within my web application.
However, I am facing an issue where the query for comments for a particular news post,
article.comments = commentService.query()
, is being sent to /api/news/comments
instead of /api/news/:id/comments
. How do I specify the :id parameter so that the request is directed to the correct URL (/api/news/:id/comments
)?
Here is the configuration for the commentService:
.factory('commentService', function($resource){
return $resource('/api/news/:id/comments/:comment', {id: '@news', comment: '@comment'}, {
update: {
method: 'PUT'
}
}, {
stripTrailingSlashes: false
}
)})
Method for fetching comments on ng-click:
$scope.getComments = function(article) {
article.comments = commentService.query()
}