Popup Alert show once


#1

Is it possible make $ionicPopup (alert) show once.

Am having this in my controller:
$scope.$on(’$ionicView.loaded’, function(event) {
$ionicPopup.alert({
title: ‘Don’t eat that!’,
template: ‘It might taste good’
});
});

I actually want it to show once (the first time the user visit the view/page).


#2

You could add a Boolean and make a conditional… If true, store to local device and show pop up, else do nothing.


#3

Thanks, please can you show me an example.


#4

Soemthing like this, but there are many ways.

add $localStorage to your controller.

   var popupShown = false;
   if(popupShown == false){
   $ionicPopup.alert({
      title: 'Don\'t eat that!',
      template: 'It might taste good',
      buttons: [
      {
         text: '<b>OK</b>',
         onTap: function() {
           console.log('shown');
           $localStorage.popupShown = true;
         }
       }]
    }); 
  }

I havent tried this as I don’t use ionic1 anymore. Please let me know if you get errors.


#5

Ok, thanks so much, I will try it.