First Launch Modal


#1

Hi,

I was wondering if it was possible to have a modal open after the first launch of an application. I would like to use it as a terms and conditions type of thing. I was not able to find what I was looking for when doing some research.

Thanks!


#2

Hi @jeff3597,

In which ionic version you want this?


#3

Preferably In ionic 3 if that is possible


#4

Hi there @jeff3597, have you seen ionic storage? I think it does the trick you’re looking for.


#5

I have tried but I have not been able to implement in correctly. Would you happen to have any sample code?


#6

As @andreven pointed out, this can be done with the storage service: https://ionicframework.com/docs/storage/. It would look like this in your app’s initialization code (untested):

this.storage.get('__modalShown').then((modalShown) => {
  if (!modalShown) {
    // open modal here

    this.storage.set('__modalShown', true);
  }
})

#7

would it go in the NgOnInit() function? Or is there a better place to put it?


#8

Use the ionViewDidEnter hook I would say. Not sure if ionViewWillEnter is ok.

See navcontroller docs

Which is not present in app.conponent.ts

Then u need to rely on angular lifecycle hooks that run after conpletion of the view. And they have a different syntax!


#10

I would actually create a function to check that on my app.component.ts