...

/

Create FormBuilder and Validators for the Register Page

Create FormBuilder and Validators for the Register Page

Creating FormBuilder and Validators for the Register page.

Creating FormBuilder for the register component

So far in this course, we’ve designed the registration form, but we’re yet to configure FormBuilder and validation. To implement this, we’ll follow the steps below:

Step 1: Import and inject the ReactiveFormsModule

The FormBuilder API uses ReactiveFormsModule and can’t work without it. To set up ReactiveFormsModule, we must import and inject it into our app.module.ts file.

{
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
  "recommendations": ["angular.ng-template"]
}
Importing the ReactiveFormsModule

As we can see above, we import the ReactiveFormsModule in line 5 and inject it into the imports array in line 27.

Step 2: Setting up the FormBuilder, FormGroup, and Validators

The FormBuilder class is used to create FormGroups, FormControls, and Validators. It provides the required API needed to make the instance of a form in Angular. To configure the FormGroups, FormControls, and ...