2
나는 데이터를 검색하고 새로운 데이터를 추가하기 위해 json-server와 함께 작동하는 앵귤러 응용 프로그램을 가지고 있습니다 (사용자 피드백). 그래서 나는 몇몇 배열을 가진 json 데이타베이스를 가지고 있고 그들 중 하나는 현재 비어있는 "feedbacks":[]
이다. PUT 방법에 나는json-server에 새 객체 추가; AngularJS
PUT /feedbacks 404
서버에서 이것은 PUT http://localhost:3000/feedbacks 404 (Not Found)
크롬이다. 이 컨트롤러입니다
angular.module('myApp')
.constant("baseURL", "http://localhost:3000/")
.service('feedbackService',['$resource','baseURL',function($resource,baseURL){
this.getFeedback=function(){
return $resource(baseURL+"feedbacks/:date",null,{
'update':{
method:'PUT'
}
});
};
}]);
:
이
내 서비스// contactus.html controllers
.controller('ContactController', ['$scope', function($scope) {
$scope.feedback = {firstName: "",lastName: "",email: "",date: ""};
}])
// Feedback form controller
.controller('FeedbackController', ['$scope', 'feedbackService', function($scope, feedbackService) {
$scope.feedbacks = feedbackService.getFeedback().query(function(response) {
$scope.feedbacks = response;
});
$scope.sendFeedback = function() {
$scope.feedback.date = new Date().toISOString();
$scope.feedbacks.push($scope.feedback);
feedbackService.getFeedback().update($scope.feedbacks);
$scope.feedbackForm.$setPristine();
$scope.feedback = {firstName: "",lastName: "",email: "", date:""};
};
}])
getFeedbacks()
방법 작품과 서버 (200)를 보낼 수는 있지만, PUT을 위해 내가 해결 404
객체에 대한
자동 증분 ID를 가지고하는 :
와도 나는에 서비스를 변경했습니다. 프런트 엔드에서 할 일이 없습니다. –
@ramamoorthy_villi이 기사를 처음 접했을 때 서비스 계층에서 무엇을 확인해야합니까? –
서버 메서드에서 작동하는 put 메서드를 확인하십시오. –