Use function in popup when button is taped


#1

Hi,

I want to use a function when a button is taped. The button is part of a popup and the function should change the value of the variable “count” to 0.

This is my code (.ts):

count:number=5;

showConfirm() {
    let confirm = this.alertCtrl.create({
      title: 'Reset Counting?',
      message: `Reset: Resets Count Variable`,
      buttons: [
        {
			text: 'Reset',
            onTap: reset(),
			handler: () => {
			console.log('Reset Clicked');
			}
		},
      ]
    });
    confirm.present();
  }

reset(){
		this.count=0;
	}

If you have any suggestions, especially code, I would be very thankfully.

Greetings,

Robert


#2

Hey @RobertLinde, Why do you have to call the “reset” function when you can easily handle your “count” variable in the provided confirm’s handler?