mardi 22 avril 2014

How to use $resource in AngularJS properly for building a client app?


Vote count:

0




I've been following this tutorial http://ift.tt/1nnyeeb. I implemented a Grails backend with it instead of the Java one in the tutorial.


I've got the data coming back and forth, with one issue. If I create/update/delete a user, I don't see the changes reflected on my user list when I am redirected back. I have to refresh the page to see the updates.


Looking at the network traffic for an edit, it looks like it does a PUT and fires off the GET before the PUT is complete. Assuming this is because $resource returns a promise so things can be done asynchronously. So how do I handle this so that when $location redirects me, my list is up to date?


I'm guessing the options are to wait for the PUT to complete before redirecting/querying for the list, or to somehow manually manage the $scope.users to match the request?


Or maybe this tutorial is just a bad example? Maybe there is a better way to do it (still using $resource)?


Note: I've seen Restangular out there, and I've seen $http with success callbacks, but I would like to understand the situation above.



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire