Search code examples
angularjsng-viewon-location-changed

$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?

Solution

  • 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;
    });