0

I'm trying to post new data comment and I want $resource serviceto give every comment unique id automatically.but I don't know how to do it . the data was past but in id was property empty ,it don't have id number.

Code for controller.js

    .controller('ContactController', ['$scope','FeedbackFactory', function($scope,FeedbackFactory) {

        $scope.feedback = {mychannel:"", firstName:"", lastName:"", agree:false, email:"" ,id:""};

        var channels = [{value:"tel", label:"Tel."}, {value:"Email",label:"Email"}];

        $scope.channels = channels;
        $scope.invalidChannelSelection = false;

                     $scope.fback= FeedbackFactory.putFeedback().query(

                        function(response){
                            $scope.fback = response;

                        },
                        function(response) {
                            $scope.message = "Error: "+response.status + " " + response.statusText;
                        }
        );

    }])




    .controller('FeedbackController', ['$scope', 'FeedbackFactory',function($scope,FeedbackFactory) {

        $scope.sendFeedback = function() {

            console.log($scope.feedback);

            if ($scope.feedback.agree && ($scope.feedback.mychannel === "")) {
                $scope.invalidChannelSelection = true;
                console.log('incorrect');
            }
            else {
                    $scope.invalidChannelSelection = false;
                  $scope.fback.push($scope.feedback);
          FeedbackFactory.putFeedback().save($scope.fback);

                $scope.feedback = {mychannel:"", firstName:"", lastName:"", agree:false, email:"" };
                $scope.feedback.mychannel="";
                $scope.feedbackForm.$setPristine();
                console.log($scope.feedback);
            }
        };
    }])

service.js

.service('FeedbackFactory',['$resource','baseURL',function($resource,baseURL){
this.putFeedback = function(){

  return $resource(baseURL+"feedback/",{'update':{method:'POST'}});  
};

   } ])

  ;

note:the data comment will save in form of JSON data.

munirah
  • 25
  • 1
  • 7
  • Possible duplicate of [ngResource retrive unique ID from POST response after $save()](http://stackoverflow.com/questions/19100323/ngresource-retrive-unique-id-from-post-response-after-save) – georgeawg Apr 15 '17 at 06:13
  • thanks .it works after I deleted this code: {'update':{method:'POST'} . – munirah Apr 16 '17 at 14:40
  • The standard action method name for HTTP POST is `.save`. Though not standard, and not supported on all REST APIs, the action method named `.update` is usually an HTTP PUT operation. – georgeawg Apr 16 '17 at 16:25

0 Answers0