Can AngularJS Listen For $locationChangeSuccess On Refresh?
I am listening for $locationChangeSuccess in Angular using this code: $scope.$on('$locationChangeSuccess', function(event) {   console.log('Check, 1, 2!'); });  However, it will on
Solution 1:
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());
    });
});
Solution 2:
You probably want a listener on window.onbeforeunload which is called just before the window unloads it's resources (refresh).
Post a Comment for "Can AngularJS Listen For $locationChangeSuccess On Refresh?"