Why isn't my alertbox working?


#1

I’m trying to get an alert box to popup when the http.get url cannot be loaded to tell the user it’s an internet connectivity issue and some features may be limited. For some reason it isn’t working.

Here’s my code:

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

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

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

#2

you are defining a function on the scope, if it would called, is creating a alert^^…

you can call $ionicpopup.alert directly


#3

Thank you :slight_smile: It’s working now.

Now i have this issue: Alert box is popping up twice?