I have an AngularJS application that uses $ resource service to retrieve data using the query () method and create new data using the model. $ Save () method. This works great, as the docs say.
My question is how to update my local data received with MyService.query (), first of all, after I changed it?
Now I have used the simplest approach, and I call the query () method again. I know that this is the worst way in terms of efficiency, but it is the easiest.
In my server side, I am returning all state representation of the new model. How to add a new model to an array of local data?
UPDATE
I end up just pushing the model back from the server, but I will still be happy to know if this is the way to go. From what I can understand from the source code, the returned array is a plan-old-javascript array that I can manipulate myself.
This is the code I used
$scope.save = function () { var newComment = new CommentsDataSource(); newComment.Content = $scope.todoText; newComment.$save({ id: "1" }, function (savedComment) { $scope.comments.push(savedComment); }); }
source share