나는 포럼에 대한 다음과 같은 기본 API를 가지고 :ngResource : 특정 항목에 POST 요청을 만들기
POST /topics
(만든 새 주제)GET /topics
GET /topics/1
(수 (모든 주제를 얻을) ID "1"을 주제)
그리고 난 다음 추가 할 :
POST /topics/1
나는 다음과 같은 코드 (관련 발췌) 시도
(ID "1"로 주제에 회신을 추가),하지만 작동되지 않았습니다
이.controller('TopicReplyController', function ($scope, $routeParams, Topics) {
'use strict';
var topicId = Number($routeParams.topicId);
Topics.get({topicId: topicId}, function (res) {
$scope.topic = res;
});
$scope.postReply = function() {
var newPost = new Topics({
topicId: topicId
});
newPost.text = $scope.postText;
newPost.$save(); // Should post to /topics/whatever, not just /topics
};
})
.factory('Topics', function ($resource) {
'use strict';
return $resource('/topics/:topicId', {topicId: '@id'});
});
그것은 단지를 만든다 /topics
으로 요청하면 작동하지 않습니다.
어떻게하면이 아이디어를 얻을 수 있습니까? $resource docs 가입일
/topics/1을 업데이트하거나 ID 1로 새로운 '주제'를 만드시겠습니까? – Adrian
/topic/1에 POST 요청을 보내야하는 ID 1의 항목에 새 게시물을 추가하려고합니다. 드문 일이지만 여전히 RESTful입니다. – callumacrae