Show alert during start of the app


#1

how to show an alert when you start your application ? it works good on click but how to initiate the alert during the start of the app.


#2

Wrap your Alert in either

onPageLoaded(){}
onPageWillEnter(){}

or
onPageDidEnter(){}

in yourr start page.

See “LifeCycle Events” at


#3

you can always rise the alert on your “first” controller, the easiest way.

.controller('FirstCtrl', function($scope, ) {

alert('Hey you!');

...
...
})

#4

thanks sir, but i think it is for Ionic 1 …can you provide the same for angularjs 2?


#5

thanks…works like a charm :smile:


#6

but one thing is there @Mobius77
when I am putting the inside the constructor, alert do come up but the main page gets totally blank.
and after pressing OK button on the alert it closes the alert and white blank page comes up.
any idea how to solve this?


#7

Do not put inside constructor :slight_smile:

constructor(private nav:NavController){
  blah blah
 }

  onPageLoaded(){
     let myAlert=Alert.create({
                            title: 'Example',
                            message: "This is an example",
                            enableBackdropDismiss:false,
                            buttons: ['OK']
                        })
     this.nav.present(myAlert);
  }