"checked" of the "ion-radio" does not work

1
<ion-list radio-group style="margin-bottom:10px;" [(ngModel)]="orcamento.tipo" name="tipo" #tipo="ngModel">

    <ion-item>
        <ion-label>Consumidor</ion-label>
        <ion-radio value="consumidor" checked="true"></ion-radio>

    </ion-item>

    <ion-item>
        <ion-label>Revenda</ion-label>
        <ion-radio value="revenda"></ion-radio>
    </ion-item>

</ion-list>

I wanted the first option of these radio inputs to be selected by default, but in the template it looks like this:

Why is the option not being selected?

    
asked by anonymous 13.07.2017 / 13:10

2 answers

0

Notice that within your ion-list has a ngModel that is where the value of the selected option will be stored, each ion-radio has a value, so you can initialize the component with a selected one, just initialize the variable "budget.type "with the ion-radio value you want to get selected, eg:

- Your component.ts -

orcamento.tipo = 'consumidor';

Adding this code in your constructor or your component's onInit should already come selected, not needing checked in html, as it will be done the ngModel value bind of the selected radio.

UPDATE

- Your component.ts -

orcamento = { tipo: 'consumidor', ... seus outros atributos de orcamento };

The error happened because your budget is an object, see where you initialize it and in the type field set with the desired ion-radio value.

Actually when you select an ion-radio it does this from behind, it adds the value of the ion-radio in ngModel, so if you initialize the value of it with a selected one, it will fetch within the ion-list which ion- radio has the value informed and will select it.

    
13.07.2017 / 14:38
0

You do not need this true, just pass the checked

<ion-radio value="consumidor" checked></ion-radio>

If not, try

<ion-radio value="orderBy1" [checked]="orderBy1">
    
13.07.2017 / 13:59