I am listening for $locationChangeSuccess
in Angular using this code:
$scope.$on(\'$locationChangeSuccess\', function(event) {
console.log(\'C
You probably want a listener on window.onbeforeunload
which is called just before the window unloads it's resources (refresh).
You can't register from within a controller because $locationChangeSuccess occurs before the route is matched and the controller invoked. By the time you register, the event has already been fired.
However, you can subscribe to the event on $rootScope during the application bootstrap phase:
var app = angular.module('app', []);
app.run(function ($rootScope) {
$rootScope.$on('$locationChangeSuccess', function () {
console.log('$locationChangeSuccess changed!', new Date());
});
});