2016-08-20 14 views
0

db.jsonファイルでjson-serverとdb.jsonを使用しています。私は現在、空の配列"feedback":[]を持っており、ユーザーはアプリからフィードバックを送信できるはずです。角型のJSONオブジェクトをサーバーにプッシュ

が、何もサーバーにプッシュされます、getメソッドは、(サーバから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:"" 
       }; 
     }; 
    }]) 

答えて

1

を有し、データ

を更新する更新メソッドを呼び出し
var feedbackService = feedbackService.getFeedback(); 
... 

$scope.feedbacks.push($scope.feedback); 
feedbackService.update($scope.feedbacks) 
関連する問題