Complete the code to create a reactive form control in Angular.
const nameControl = new FormControl([1]);Reactive forms use FormControl to create form controls with initial values. An empty string '' is a common initial value for text inputs.
Complete the code to add a required validator to a reactive form control.
const emailControl = new FormControl('', [1]);
The Validators.required ensures the form control must have a value before the form is valid.
Fix the error in the reactive form group declaration.
this.form = new FormGroup({
username: new FormControl('', [1])
});Adding Validators.required ensures the username field cannot be empty, which is a common requirement.
Fill both blanks to create a reactive form group with two controls and validators.
this.loginForm = new FormGroup({
email: new FormControl('', [1]),
password: new FormControl('', [2])
});The email control needs Validators.email to check format, and the password control needs Validators.minLength(6) to ensure a minimum length.
Fill all three blanks to create a reactive form with controls, validators, and a submit handler.
this.profileForm = new FormGroup({
firstName: new FormControl('', [1]),
age: new FormControl('', [2]),
email: new FormControl('', [3])
});First name is required, age must be at least 18, and email must be valid format.