Open IonicModal on page load

Hey all,

I wanna do a modal popping up the first time you load the App and then never again after you press the button.

so this is what I was looking for : http://codepen.io/calendee/pen/oCLJF
but how do I add a function to close the modal and not open again next time if you open up the page/app ?

You can set a variable in localStorage and only show the modal if it isn’t set. See this post: http://stackoverflow.com/a/29280073/3802466

1 Like

thx @brandyshea

but if I’m using this:

if(!localStorage.getItem('agbModal')){
  $scope.modal.show();
  localStorage.setItem('agbModal', true);
}

I’m getting TypeError: Cannot read property ‘show’ of undefined.

Ah, you may want to move it to the then function, to make sure it is created:

.then(function (modal) {
    $scope.modal = modal;
    if(!localStorage.getItem('agbModal')){
        $scope.modal.show();
        localStorage.setItem('agbModal', true);
    }
});