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