Angular 11 Reactive Forms Validation Example

By Hardik Savani | November 25, 2020 | Category : Angular


I am going to show you example of angular 11 reactive forms validation. i explained simply step by step angular 11 forms validation example. i explained simply step by step angular 11 reactive forms example. step by step explain reactive form validation in angular 11. follow bellow step for angular 11 form validation example.

Reactive forms provide a model-driven approach to handling form inputs whose values change over the time. In Reactive forms, we need to import "ReactiveFormsModule" from angular forms library. we will use FormControl, FormGroup, FormArray, Validation classes with Reactive forms in angular 11 app.

If you have simple and basic form in your angular 11 application then i will prefer to use Reactive forms in angular. here i write simple example of Reactive forms with validation in angular 11.

You need to follow bellow step to create reactive forms in angular 11.

Step 1: Install Angular App

Here, in this step you need to create new ng app for this demo. if you have already created then don't create new angular 11 app.

ng new my-new-app

Step 2: Import FormsModule

If you want to create form in angular app then you need to import FormsModule from @angular/forms library. so let's add following code to app.module.ts file.


import { BrowserModule } from '@angular/platform-browser';

import { NgModule } from '@angular/core';

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

import { AppComponent } from './app.component';


declarations: [



imports: [





providers: [],

bootstrap: [AppComponent]


export class AppModule { }

Step 3: Form with ngModel

In this step, we will write code of html form with ngModel. so add following code to app.component.html file.

I used bootstrap class on this form. if you want to add than then follow this link too: Install Boorstrap 4 to Angular 11.


<h1>Angular 11 Reactive Forms Validation Example -</h1>

<form [formGroup]="form" (ngSubmit)="submit()">

<div class="form-group">

<label for="name">Name</label>






<div *ngIf=" &&" class="alert alert-danger">

<div *ngIf="">Name is required.</div>

<div *ngIf="">Name should be 3 character.</div>



<div class="form-group">

<label for="email">Email</label>






<div *ngIf=" &&" class="alert alert-danger">

<div *ngIf="">Email is required.</div>

<div *ngIf="">Please, enter valid email address.</div>



<div class="form-group">

<label for="body">Body</label>







<div *ngIf="f.body.touched && f.body.invalid" class="alert alert-danger">

<div *ngIf="f.body.errors.required">Body is required.</div>



<button class="btn btn-primary" type="submit">Submit</button>


Step 4: updated Ts File

In ts file. we will write submit() and get all input fields values. so let's add following code to app.component.ts file.


import { Component } from '@angular/core';

import { FormGroup, FormControl, Validators} from '@angular/forms';


selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']


export class AppComponent {

form = new FormGroup({

name: new FormControl('', [Validators.required, Validators.minLength(3)]),

email: new FormControl('', [Validators.required,]),

body: new FormControl('', Validators.required)


get f(){

return this.form.controls;






Now you can run your application using following command:

ng serve


{name: "Hardik Savani", email: "[email protected]", body: "This is a test"}

I hope it can help you...

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: