0

I am using json-server and db.json, in db.json file I have a currently empty array "feedback":[] where user should be able to send feedbacks from the app.

but nothing get pushed into server, the get method works (GET from server) but no PUT

this is my service:

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'
          }
        });
      };
    }]);

and this is the controller: the contactus.html contains a feedback form and hence has two controllers

// 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:""
                };
        };
    }]) 
0

2 Answers 2

1

after pushing a new feedback, call update method to update the data

var feedbackService = feedbackService.getFeedback();
...

$scope.feedbacks.push($scope.feedback); 
feedbackService.update($scope.feedbacks)
Sign up to request clarification or add additional context in comments.

Comments

0

after using POST and POT methods in service I realized there was no need any changes in service just a bit change in controller the answer to the same question in different approach

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.