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.
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.
Share Improve this question edited Apr 22, 2013 at 7:05 arnaud.breton asked Apr 22, 2013 at 6:04 arnaud.bretonarnaud.breton 2,1142 gold badges27 silver badges39 bronze badges3 Answers
Reset to default 6I believe $locationChangeStart fires when you would like it to.
you could use:
$scope.$on('$routeChangeStart', function(next, current) {
//broadcasted before a route change
// do something here
});
See more of it on : $route
Keep a model of the dirty state in a parent controller, mon 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.