How correctly bind data to radio buttons in Angular2?
You don't need [checked]
. Try with [(ngModel)]
. Also, use [value]="1"
instead of value="1"
<input type="radio" name="Coverage" [value]="1"
[(ngModel)]="formdata.coverage_verified" />Yes
This works in my case. I removed [(ngModel)]
<div class="radio">
<label>
<input type="radio"
value="1"
[checked]="model.ForeignCompany.ProfitCode === 1"
id="point1"
(change)="onProfitSelectionChange(1)"
name="ProfitCode"><small>description</small>
</label>
</div>
<div class="radio">
<label>
<input type="radio"
value="2"
[checked]="model.ForeignCompany.ProfitCode === 2"
id="point2"
(change)="onProfitSelectionChange(2)"
name="ProfitCode"><small>description</small>
</label>
</div>
and TS method looks like:
onProfitSelectionChange(entry): void {
this.model.ForeignCompany.ProfitCode = entry;
}