I need help with pre-selecting the first radio button from a generated list of radio buttons that can be changed if user selects a different radio btn…
I get the dates from an API and this is the model of the data:
then, you should check your item, it looks undefined, you must understand where it gets a value, if it gets one
my suggestion is using some console.log and following your component’s flow
<ion-list class="dates-list">
<ion-radio-group [value]="preSelectedDate" (ionChange)="radioGroupChange($event)" [(ngModel)]="selectedValue">
<ion-item *ngFor="let date of dates;let i = index" (click)="modal.dismiss()">
<ion-icon name="today-outline"></ion-icon>
<ion-label class="{{date.color}}">{{date.date_name}} {{ date.date }}</ion-label>
<ion-radio slot="end" [value]="date.date"></ion-radio>
</ion-item>
</ion-radio-group>
</ion-list>
I have tried adding this: checked="{{ i === 0 ? 'true' : '' }}" to and I tried adding this: class=“{{ i == 0 ? ‘ion-item-checked’ : ‘’ }}” to but the checkmark did not appear
You were right! I changed the [(ngModel)]=“selectedValue” to [(ngModel)]=“preSelectedDate” and now the first radio is checked and I get its value in console log.