-2

I am having issues with radio button with ngModel when I am populating with ngFor

  1. Radio button selection is misbehaving
  2. In the console.log of Form, i see the value of gender is "it"

enter image description here

What am I doing wrong Here is my code

app.component.ts 

gender :string[] = ["Male", "Female"];

app.component.html

<div class="radio" *ngFor="let it of gender">
   <label><input ngModel type="radio" name="gen"  value="it">{{it}}</label>
</div> 

1 Answers1

0

I found the answer after playing around, issue is with the 'value' of radio button, it has to be property binded

<div class="radio" *ngFor="let it of gender">
   <label><input ngModel type="radio" name="gen"  [value]="it">{{it}}</label>
</div> 

or

<div class="radio" *ngFor="let it of gender">
   <label><input ngModel type="radio" name="gen"  value={{it}}>{{it}}</label>
</div>