Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have a json file named db.json which is like

{
"menu":[
 {
   "id":0,
   "item":"item1"
},{
   "id":1,
   "item":"item2"
},{
   "id":2,
   "item":"item3"
}
],
"feedback":[]
}

I am using angular $resource to PUT an Javascirpt object into the feedback array.

Here is my service code-

this.getFeedbacks = function(){
            return $resource(baseURL + "feedback/:id", null, {
                'update': {
                    method: 'PUT'
                }
            });
        };

And here is the controller code-

$scope.fb.push($scope.myFeedback);
 menuFactory.getFeedbacks().update({
            id: $scope.fb.id
        }, $scope.fb);

Notice that the feedback array in the json is empty and the $scope.myFeedback is found from a ng-controller's ng-model and this ng-controller has a submit button when I click on the submit button then the values of the inputs are stored into the json file.
The HTML code is-

<form name="feedbackForm" ng-submit="setFeedback()">
   <input type="text" name="name" ng-model="myFeedback.name">
   <input type="submit" name="submit" value="feedback">
</form>

My update function is not working why please someone explain it. Note that I am very beginner at angularJS platform and REST client-server networking.

share|improve this question
    
Could you please provide a fiddle for better understanding? – Kushal 22 hours ago
    
You can't post data to a static resource file. That file can only be modified by a server side programming language. What is value of baseUrl? – charlietfl 22 hours ago
    
I said i am very beginner at this sector. I just want to save the value in the json file which I find from name text field. – Sajeeb Ahamed 22 hours ago
    
What programming language is your server running? – charlietfl 22 hours ago
    
I am using json-server – Sajeeb Ahamed 22 hours ago

First of all, watch browser console. It often gives you hints, where to look for the error. Coming back to the problem: try using $update instead of update.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.