Recently, I've been exploring the use of the setInterval Javascript command. It's been working smoothly for me, but now I want to find a way to stop it when the user navigates away from the page.
I found this handy code snippet: http://jsfiddle.net/PQz5k/
It effectively detects when a user leaves a page by clicking on a link to go to a different HTML page or URL, or even if they reload the current page.
However, I encountered an issue when trying to implement this functionality in an AngularJS setting. For instance, transitioning between template1.html and template2.html made it difficult to execute certain Javascript actions within Controller1.js upon leaving template1.html. Does anyone know the AngularJS equivalent of the following standard Javascript code? Please see below:
$(window).on('beforeunload', function() {
return 'Your own message goes here...';
});