我在db.json文件中使用json-server和db.json我有一個當前爲空的數組"feedback":[]
,用戶應該能夠從應用程序發送反饋。Angular,將JSON對象推送到服務器
,但沒有將被推入服務器,GET方法的工作(從服務器獲得),但沒有PUT
這是我的服務:
angular.module('confusionApp')
.constant("baseURL", "http://localhost:3000/")
.service('feedbackService',['$resource','baseURL',function($resource,baseURL){
this.getFeedback=function(){
return $resource(baseURL+"feedback/",null,{
'update':{
method:'PUT'
}
});
};
}]);
,這是控制器:該contactus.html包含一個反饋形式,並因此有兩個控制器
// 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();
$scope.sendFeedback = function() {
$scope.feedback.date=new Date().toISOString();
$scope.feedbacks.push($scope.feedback);
$scope.feedbackForm.$setPristine();
$scope.feedback = {
firstName: "",
lastName: "",
email: "",
date:""
};
};
}])