Reputation: 463
If a user hits refresh, I want to call an angular service to save their work, and upon completion of the save (asynchronous call), only then should the page refresh. How can I achieve this?
So far I've tried calling the save service outside angular, using window.onbeforeunload. But no luck. Any general advice on how to approach this? How does Angular handle page refreshes?
Upvotes: 0
Views: 1977
Reputation: 2927
there is an event called $routeChangeStart
you can simply bind the handler when the route is about to change, it should work also for refreshing the page
$scope.$on('$routeChangeStart', function() {
//callback
});
Upvotes: 2