Reputation: 2114
I'm struggling to handle the back button and ask confirmation to the user, if app state is dirty. Closing tab and reload is already handled via the onbeforeunload
hook.
I've played with $routeChangeStart
, $beforeRouteChange
, etc. but can't handle it correctly.
With $routeChangeStart
, the route is effectively changed before my callback is called.
What is the correct way to handle this situation?
Thanks for your help.
Upvotes: 2
Views: 4186
Reputation: 5545
Keep a model of the dirty state in a parent controller, common to all views? An alert/confirm appears if a dirty state is detected by any view's controller, with a "Cancel" button that resets $location.path(...) to the dirty page.
Upvotes: 1
Reputation: 100205
you could use:
$scope.$on('$routeChangeStart', function(next, current) {
//broadcasted before a route change
// do something here
});
See more of it on : $route
Upvotes: 2