Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get the selected value in ion-alert radio alert

async presentAlertRadio(heading:string){
    const alert = await this.alertCtrl.create({
      header: heading,
      inputs :[
        {
          name : 'Radio 1',
          type: 'radio',
          label: 'Radio 1',
          value: 'value1',
          checked: true
        },
        {
          name: 'radio2',
          type: 'radio',
          label: 'Radio 2',
          value: 'value2'
        },
      ],
      buttons: [
        {
          text: 'Cancel',
          role: 'cancel',
          cssClass: 'secondary',
          handler: () => {
            console.log('Confirm Cancel');
          }
        }, {
          text: 'Ok',
          handler: (data) => {
            console.log('Confirm Ok', data);
          }
        }
      ]
    });
    await alert.present();
  }

i want to assign the value of the selected radio in my alert controller to a variable, how can i access it.

new to ionic 4 so don't really know

i want to assign my var x = selectedRadio

like image 927
Karim Tingdis Avatar asked Jan 25 '26 08:01

Karim Tingdis


1 Answers

      text: 'Ok',
              handler: (data) => {
                console.log('Confirm Ok', data); //handle data here eg.
                this.x = data.value1; // this assigns your veritable 'x' to the value 
                                      // of Radio 1
}

comment if this needs clarifying

like image 84
Ira Watt Avatar answered Jan 28 '26 03:01

Ira Watt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!