alertController.create call another function on Okay

Hi,

Sorry I am very green and new to ionic but getting there slowly. I cant find on google or this forum an answer to my question…

  emergency() {
    this.loaderService.show('Alerting neighbors...');
// Inside here we take some other actions
}
    async presentAlertConfirm() {
      const alert = await this.alertController.create({
        cssClass: 'my-custom-class',
        header: 'EMERGENCY!',
        message: 'Confirm to send alerts to neighbors with your location and dial <strong>111</strong>!!!',
        buttons: [
          {
            text: 'Cancel',
            role: 'cancel',
            cssClass: 'secondary',
            handler: () => {
              console.log('Confirm Cancel: cancelled sending alerts');
            }
          }, {
            text: 'Okay',
            handler: (EMERGENCY) => {
              console.log('Confirm Okay');
              //emergency();
              //this.callNumber.callNumber("111", true)
              // .then(res => console.log('Launched dialer!', res))
              // .catch(err => console.log('Error launching dialer', err));

            }
          }

I cant seem to find how to have the “Okay” button call the emergency function.

Many thanks in advance
Barry

Rebuild again from the doc? Is the doc example working for you?

I don’t think you pasted the full core, or you made mistakes closing the create action

    const alert = await this.alertController.create({
      cssClass: 'my-custom-class',
      header: 'Confirm!',
      message: 'Message <strong>text</strong>!!!',
      buttons: [
        {
          text: 'Cancel',
          role: 'cancel',
          cssClass: 'secondary',
          handler: (blah) => {
            console.log('Confirm Cancel: blah');
          }
        }, {
          text: 'Okay',
          handler: () => {
            console.log('Confirm Okay');
          }
        }
      ]
    });

    await alert.present();

This I miss at least, but may not account for your issue

    ]
    });

    await alert.present();

Sorry just forgot to include as paste.

The code works and I get the popup; just not sure how to action the emergency() if someone clicks “Okay”.

My suggestion is to stop finding the error and use the working doc example to build up again

Does the ok handler work with u using the doc example?

Once u have it to work, u know where u went wrong

The code u provide at first glimp does not indicate anything

Problem resolved, I needed to use

          this.emergency()

Ok. now it is getting it a bit clearer.

Can you present the full code of the component where all this is residing?

Probably has to do with the way you have defined your class, which isn’t an Ionic alert thing, but potential issues in the way you handle typescript-javascript (or maybe even angular)