I have a JSON file called db.json with the following structure:
{
"menu":[
{
"id":0,
"item":"item1"
},{
"id":1,
"item":"item2"
},{
"id":2,
"item":"item3"
}
],
"feedback":[]
}
Currently, I am using Angular's $resource
to send a JavaScript object to the feedback
array using the PUT
method.
Below is my service code-
this.getFeedbacks = function(){
return $resource(baseURL + "feedback/:id", null, {
'update': {
method: 'PUT'
}
});
};
And this is the controller code-
$scope.fb.push($scope.myFeedback);
menuFactory.getFeedbacks().update({
id: $scope.fb.id
}, $scope.fb);
In the JSON, the feedback
array is initially empty. The value for myFeedback
comes from an ng-model within a specific ng-controller in the HTML form. Upon clicking a submit button, the input values are stored in the JSON file.
The relevant HTML code is as follows-
<form name="feedbackForm" ng-submit="setFeedback()">
<input type="text" name="name" ng-model="myFeedback.name">
<input type="submit" name="submit" value="feedback">
</form>
I am encountering issues with my update function. Could someone please explain why? Please bear in mind that I am new to both AngularJS and REST client-server networking.