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() {
    .success(function(data) {
      $ = data;
      window.localStorage.setItem("data", JSON.stringify(data));

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

    .then(function() {

Why isn't my alertbox working?

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


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?