Alert box is popping up twice?


#1

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

Why isn't my alertbox working?
#2

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


#3

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


#4

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?