Kalpana K Kalpana K - 2 months ago 26
AngularJS Question

$locationChangeStart is not working in firefox

$scope.$on("$locationChangeStart", function (event, next, current) {

if (!$rootScope.isPopupOpen) {

if ($rootScope.isUrlLoad) {

window.location.reload();

}
}

$rootScope.isUrlLoad = true;

});

In other browser,i have no problem for loading..But in firefox it continuously loading.can anyone please suggest me?

Answer

Your problem it's probably related to the fact $locationChangeStart it's called even the first time your page load.

Simply get rid of this issue with a flag:

var firstTime = true;
$scope.$on("$locationChangeStart", function (event, next, current) {

    if(firstTime){
       firstTime = false;
       event.preventDefault();
       return;
    }

    if (!$rootScope.isPopupOpen) {

        if ($rootScope.isUrlLoad) {

           window.location.reload();

        }
    }
    $rootScope.isUrlLoad = true;
});