Angular · Junior · Question 46 of 75
How do you connect a reactive form to the template?
form = new FormGroup({
email: new FormControl("", { nonNullable: true, validators: [Validators.required, Validators.email] }),
});- ✓Correct answer:
<form [formGroup]="form">and<input formControlName="email" />withReactiveFormsModuleimported - 2
<form [(ngModel)]="form"> - 3
<input value="{{ form.email }}" />
Explanation
Directives from ReactiveFormsModule link the DOM to the controls. The value is in form.value (or getRawValue()) and the validity in form.valid.