Angular – Error Cannot find name ‘FormGroup’ – Solved

Today, I would like to show you Cannot find name ‘FormGroup’ in angular. I would like to share with you angular error ts2304 cannot find name ‘FormGroup’. We will use angular cannot find FormGroup error. you can see angular cannot find name FormGroup.

You can use this solution with angular 8, angular 9, angular 10, angular 11, angular 12 and angular 13 version.

In this post, I will give you the solution of “Cannot find name ‘FormGroup'” in angular application. we need to import FormGroup from @angular/forms library. so let’s see below the solution and full code.

Error Preview:

Angular - Error Cannot find name 'FormGroup' - Solved

.medrectangle-3-multi-157{border:none!important;display:block!important;float:none;line-height:0;margin-bottom:15px!important;margin-left:0!important;margin-right:0!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:300px;padding:0;text-align:center!important}

Solution:

let’s import FormGroup from @angular/forms npm package, as bellow:

Import FormGroup:

import { FormGroup } from '@angular/forms';

Let’s see bellow working code:

Example:

.medrectangle-4-multi-155{border:none!important;display:block!important;float:none;line-height:0;margin-bottom:15px!important;margin-left:0!important;margin-right:0!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:300px;padding:0;text-align:center!important}

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

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

@Component({

selector: 'app-root',

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

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

})

export class AppComponent implements OnInit{

title = 'my-new-app';

ngOnInit() {

this.title = "Title Updated";

}

form = new FormGroup({

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

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

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

});

get f(){

return this.form.controls;

}

submit(){

console.log(this.form.value);

}

}

I hope it can help you…

Leave a Comment