I have a string like this
values="value1~Display Value 1\nvalue2~Display Vaue 2"
And I need to display this string as radio button options in ionic for that I am converting this string to array like this
getItems() {
let newValues = [];
let arr = this.values.split("\n");
for (let i = 0; i < arr.length; i++) {
let keyValues = arr[i].split("~")
newValues.push({
"value": keyValues[0],
"displayValue": keyValues[1]
})
}
return newValues;
}
My html template looks like this
<form [formGroup]="formGroup">
<ion-list radio-group formControlName="radioButton">
<ion-item *ngFor="let item of getItems()">
<ion-label>{{item.displayValue}}</ion-label>
<ion-radio [value]="item.value"></ion-radio>
</ion-item>
</ion-list>
</form>
So when I use function binding with *ngFor, the radio button is not getting selected but if I use normal array in *ngFor everything works perfectly.
I have reproduced the problem here stackblitz.
Can anyone help??