In AngularJS, how to detect when user leaves template/page?
问题 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