Please see this code snippet from the docs:
When using radio buttons in a reactive form, ...
import {Component} from '@angular/core';
import {FormControl, FormGroup} from '@angular/forms';
@Component({
selector: 'example-app',
template: `
<form [formGroup]="form">
<input type="radio" formControlName="food" value="beef" > Beef
<input type="radio" formControlName="food" value="lamb"> Lamb
<input type="radio" formControlName="food" value="fish"> Fish
</form>
<p>Form value: {{ form.value | json }}</p> <!-- {food: 'lamb' } -->
`,
})
export class ReactiveRadioButtonComp {
form = new FormGroup({
food: new FormControl('lamb'),
});
}
My question: What should I do to make one of those radio buttons checked by default? Do I need to add some additional property to the FormControl? Or should I modify something in the template?
(I tried adding a checked attribute to one of them in the template, but for some reason it doesn't do anything. I looked at it in the browser using "Inspect element", and the attribute is there in the DOM, yet it has no effect on the state of the radio button. It doesn't become checked.)