Reputation: 711
Actually, I want to be able to handle page refreshing from AngularJS directly and not from plain JS with the following known solution:
window.onbeforeunload = function () {
// handle the exit event
};
I found that we can detect it with ngRoute by using the following event listener:
$rootScope.$on('$routeChangeStart', function (event, next, current) {
if (!current) {
// handle session start event
}
});
But I'm not using this router for my application. I am working with angular-ui-router 1.x. And events have been deprecated in favor of transitions hooks (cf. https://github.com/angular-ui/ui-router/wiki#state-change-events)
I can't find a way to detect browser refresh using angular-ui-router 1.x. If anyone have an idea to do that, it would be great !
Thanks in advance
Upvotes: 0
Views: 819
Reputation: 5998
I my own solution I created directive that uses onbeforeundload native event and set it to html body. This give me desired ability and integrated it into angular live cycle so I can gen any service or other angular staff with it.
Upvotes: 0