From the course: Building Applications with Angular, ASP.NET Core, and Entity Framework Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Reactive forms with FormBuilder

Reactive forms with FormBuilder

From the course: Building Applications with Angular, ASP.NET Core, and Entity Framework Core

Start my 1-month free trial

Reactive forms with FormBuilder

- [Instructor] There are several ways to achieve form validation with Angular2. The more traditional method of template validation involves putting your validation logic or parameters inside the template or the HTML itself. The other way is with Reactive forms, or Model-driven forms. This is where we create the model of what we expect out of the form, and the model itself will contain the validation rules. Let's begin by opening up our register.component.ts. Then below line 1, lets import { FormBuilder } from '@angular/forms'. Then let's create the new property in our class called form. That way we can bind that to our HTML form. So above the constructor, I'll create it and call it form. Then inside our constructor, let's inject FormBuilder. And I'll call it fb for FormBuilder. Then inside the constructor, let's create a FormBuilder group. So we'll start with this.form = fb.group. Inside here, we'll need to pass in an object that defines our form model. So let's start with email, and…

Contents