We have the radio button group and try to make the default selection for Female Radio option.
<ng-template #genderTemplate>
<div>
<div>
<label class="ari-label" for="gender">Gender</label>
</div>
<label class="ari-control ari-control-radio ari-control-inline">
<input formControlName="gender" type="radio" [value]="true" /> Male
<div class="ari-control-indicator"></div>
</label>
<label class="ari-control ari-control-radio ari-control-inline">
<input formControlName="gender" type="radio" [value]="false" [checked]="!gender"/> Female
<div class="ari-control-indicator"></div>
</label>
</div>
</ng-template>
It is not working. Any clue?
2
Answers
You will have add name="gender" in html
Too in the .ts add gender:boolean=false;
To your HTML template, I added the name attribute to group the radio buttons together. I changed the value of male to ‘male’ and the value of female to ‘female’. Then I set the default value for the gender formControl in Typescript to ‘female’, so the female button will be selected initially.
Better would be to initialize an enum for the gender types.
Therefore, your template should look something like:
Typescript form group: