Thach Huynh
Thach Huynh

Reputation: 1293

Prevent radio button from being checked but cannot get RadioButton component object from ionSelect ion-radio

I want to prevent the radio button from being checked if ionSelect function does not perform as I expected.

I cannot get the $event of ionSelect function of ion-radio tag as a RadioButton component so I can set the checked value to false if I want.

here is my code:

            <ion-list radio-group>
                <ion-item class="item-child">
                    <ion-label>Manual</ion-label>
                    <ion-radio item-start (ionSelect)="changeMode($event)" color="secondary"></ion-radio>
                </ion-item>
                <ion-item class="item-child">
                    <ion-label>Auto</ion-label>
                    <ion-radio item-start (ionSelect)="changeMode($event)" color="secondary"></ion-radio>
                </ion-item>
            </ion-list>

ts file:

import { RadioButton } from 'ionic-angular';

        public changeMode(event: RadioButton) {
            console.log(event);
    }

it logs like this rb-11-0

I updated the latest version of ionic-angular but it still happens. I tried with

public changeMode(event: any) {
    console.log(event);

} but still the same log result.

What is the problem ?

Upvotes: 0

Views: 324

Answers (1)

CodeChanger
CodeChanger

Reputation: 8351

As per your requiremnets you need to pass value in your changeMode like below :

<ion-list radio-group>
        <ion-item class="item-child">
            <ion-label>Manual</ion-label>
            <ion-radio item-start (ionSelect)="changeMode('manual')" color="secondary"></ion-radio>
        </ion-item>
        <ion-item class="item-child">
            <ion-label>Auto</ion-label>
            <ion-radio item-start (ionSelect)="changeMode('auto')" color="secondary"></ion-radio>
        </ion-item>
    </ion-list>

change your method :

  public changeMode(value: string) {
    console.log(value);
  }

log of your value :

manual
auto

Hope this will helps.

Upvotes: 1

Related Questions