Complete the code to bind the form control to the input field.
<input type="text" [formControl]="[1]">
The [formControl] directive binds the input to the specified FormControl instance.
Complete the code to check if the form control is invalid and touched.
<div *ngIf="[1].invalid && [1].touched">Please enter a valid value.</div>
We check the invalid and touched properties on the FormControl instance to show errors only after user interaction.
Fix the error in the code to display the required error message.
<div *ngIf="[1].errors?.required">This field is required.</div>
The errors property is on the FormControl instance, so use the variable name.
Fill both blanks to create a form group with a required validator.
this.form = new FormGroup({ name: new FormControl('', [[1]]) });
<input type="text" [formControlName]="[2]">The first blank needs the required validator function. The second blank is the control name string used in the template.
Fill all three blanks to show an error message only when the control is invalid, touched, and has a required error.
<div *ngIf="[1].invalid && [2] && [3].errors?.required">Name is required.</div>
The first and third blanks are the FormControl variable. The second blank checks if the control was touched.