I am using the Javascript command: setInterval. I like to stop it when the user leaves the page.
This code seems to work well: http://jsfiddle.net/PQz5k/
It detects when a user leaves a page. It executes Javascript code when a user clicks on a link to go to a different HTML page or URL, or if user reloads page.
However, it does not work when I go from one AngularJS template to another. As an example, if I am at template1.html, I want the Javascript code to do something in Controller1.js when the user leaves template1.html to go to template2.html. What is the equivalent of this code below in AngularJS?:
$(window).on('beforeunload', function() {
return 'Your own message goes here...';
});