Alert box is popping up twice?

I’m trying to display an alert popup box when my function fails to load a http.get request.

Initially the alert popup box was popping up 3 times. So i added a variable called popupShow = false and put the alert box inside a if(!popupShow) statement and called popupShow = true once the alertbox as been excuted. Now the alertbox pops up twice. I’m unsure why it is doing this.

$scope.doRefresh = function() {
  $http.get('')
    .success(function(data) {
      $scope.data = data;
      window.localStorage.setItem("data", JSON.stringify(data));
    })

    .error(function() {
    if(!popupShow){
      $ionicPopup.alert({
          title: 'Internet Connectivity',
          template: 'Some features will be limited'
        })
      popupShow = true;
    }
      $ionicLoading.hide()
      if(window.localStorage.getItem("data") !== undefined) {
        $scope.data = JSON.parse(window.localStorage.getItem("data"));
      }
    })

    .then(function() {
      $ionicLoading.hide()
    });
  }

inspect your requests beeing sent.
Maybe your doRefresh-function is called multiple times… and if the function is called parallel -> you get the popup twice because popupShow is for both false

1 Like

Thank you, I’ve fixed the problem now. It was because I was calling my controller twice.

iam having multiple states and i have to display the ionicpopup based on the respected controllers but while viewing other state’s controller is also executing and showing popup which is defined in the other state. iam struck here and dont know what to do now?