How to use ion-radio?


#1

I have the next code and I’m trying to get the value of my ion-radio, but I can’t.

How I can get the value in the ts (typescript).

If you need more info ask me.

<div class="Pregunta" >
    <p>Question 1</p>
    <ion-list radio-group  [(ngModel)]="val">
        <ion-item>
          <ion-label color='secondary'>Bueno</ion-label>
          <ion-radio value="bueno" color='secondary'></ion-radio>      
        </ion-item> 
        <ion-item>
          <ion-label color='amarillo'>Regular</ion-label>
          <ion-radio value="regular" color='amarillo'></ion-radio>      
        </ion-item>
        <ion-item>
          <ion-label color='danger'>Malo</ion-label>
          <ion-radio value="malo" color="danger"></ion-radio>      
        </ion-item>
    </ion-list>
</div>

How to use ngFor with ngModel
#2

I think the “value” attribute in ion-radio need to be as “[value]”.


#3

Thanks gauz09.
Sorry, I’m using native plugins, but every time I make a change I have to build the apk and put it on my cellphone, you know another way to test it?


#4

If you are using native features then you can go with emulators as the first pass but you will certainly need to use a real device at some point in time.

Having said that, it takes just a little longer to get the app on your mobile by enabling developer options on your android device and running your app on the device by using “ionic run android”. Or perhaps I got used to the time it takes as I start doing something else. :slight_smile:

I remember reading somewhere about having “watch” sending changes to the device instead of building the whole thing again. Or maybe I just read somebody posting a question if that is possible, can’t recollect.

For iOS, I am currently using Ionic View (for lack of time setting up Mac with “ionic run ios”).

Hope this helps.


#5

The comment currently marked as the accepted solution makes no sense. There is nothing wrong with the code in the OP (although I dislike using single quotes on HTML attributes).


#6

I do not know what problem I had, but I deleted my view and rewrote it and it was fixed. I send it tomorrow the view and a method in ts