I have to make a ion radio checked automatically based on the data in a list.
this is my code:
<div *ngFor="let item of prelevementToDisplay">
<ion-list radio-group *ngFor="let type of normePrelevementList; let i = index" [(ngModel)]="checkNorme">
<div *ngIf="type.name === item.normePrelevement">
<ion-item>
<ion-label>{{type.name}} </ion-label>
<ion-radio [checked]="true" value="{{type.name}}"></ion-radio>
</ion-item>
</div>
<div *ngIf="type.name!== item.normePrelevement">
<ion-item>
<ion-label>{{type.name}}</ion-label>
<ion-radio value="{{type.name}}"></ion-radio>
</ion-item>
</div>
</div>
nothing change. How can i resolve it ?
checked based on what exactly?
if the type.name === item.normePrelevement then the ion radio will be checked
but only one radio can be checked at once
checked="type.name === item.normePrelevement"
I romove the ngif. I try with your proposition. It seems to be rational but nothing changed: the ion radio is not checked.
i test the equality by using {{type.name === item.normePrelevement}}.
It display true but the radio button is not checked
I see, but I dont know why it doesnt work this way
I figure out the problem.
<ion-list radio-group *ngFor="let type of normePrelevementList; let i = index" [(ngModel)]="checkNorme">
<ion-item>
<ion-label>{{type.name}} </ion-label>
<ion-radio [checked]="true" value="{{checkNorme}}"></ion-radio>
</ion-item>.....
update
i undestrand know the strange behaviour. The value of ngmodel is null.
we need to set the checkNorme before we expose the dom
<ion-list radio-group *ngFor="let type of normePrelevementList; let i = index" [(ngModel)]="checkNorme">
<ion-item>
<ion-label>{{type.name}} </ion-label>
<ion-radio value="{{type.name}}"></ion-radio>
</ion-item>.....