Perform an action when the 'Accept' button is pressed

0

Personal I'm 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 in the Alert PopUp? I want the user to be redirected to HomePage. When the button is there in the html I know how to do it, but in Alert I have no idea, I have already looked at documentation and nothing.

Mybuttonin.html

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

My button in .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();
}
    
asked by anonymous 28.09.2018 / 17:05

1 answer

0

You need to include the action you want within%% of "I Accept". For example, to navigate to HomePage, you can include handler .

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();
}
    
29.09.2018 / 15:36