Perform an action when the 'Accepted' button is pressed

Asked

Viewed 224 times

0

I am making an App in Ionic and when the user presses the Exit button I was able to configure an Alert message, but how do I configure the "I Accept" button of the Alert Popup? I want the user to be redirected to the homepage. When the button is there in html I know how to do, but in Alert I have no idea, I’ve looked at documentation and nothing.Esta é a imagem do App

My button in . html

<button class="p4" ion-item (click)="showConfirm()"><img class="img4" 
src="../../assets/imgs/logout.png">Sair</button>

My button on . ts

function showConfirm() {
    const confirm = this.alertCtrl.create({
        title: 'Deseja Realmente Sair ?',
        message: 'Você será redirecionado para a PáginaPrincipal',
        buttons: [
            {
                text: 'Não Aceito',
                handler: () => {
                    console.log('Disagree clicked');
                }
            },
            {
               text: 'Aceito',
               handler: () => {
                  console.log('Agree clicked');
               }
           }
       ]
  });
  confirm.present();
}

1 answer

0

You need to include the action you want within the handler of the "I Accept". For example, to navigate to the Homepage, you can include this.navCtrl.push("HomePage");.

function showConfirm() {
    const confirm = this.alertCtrl.create({
        title: 'Deseja Realmente Sair ?',
        message: 'Você será redirecionado para a PáginaPrincipal',
        buttons: [
            {
                text: 'Não Aceito',
                handler: () => {
                    console.log('Disagree clicked');
                }
            },
            {
               text: 'Aceito',
               handler: () => {
                  console.log('Agree clicked');
                  this.navCtrl.push("HomePage");
               }
           }
       ]
   });
   confirm.present();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.