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, angular 13, angular 14, angular 15, angular 16 and angular 17 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:
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:
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Angular 13 Reactive Forms Validation Tutorial Example
- Angular Get Current Date and Time Example
- Angular Material Carousel Slider Example
- Angular Owl Carousel/Slider Example Tutorial
- Angular 11 Bubble Chart using ng2-charts Example
- Angular Bar Chart Example Tutorial
- Angular Line Chart Example Tutorial
- Angular Material Autocomplete with API Example
- Angular Material Input Autocomplete Example
- Angular Material Date Range Picker Example
- Angular Textarea Auto Height Example
- Angular Scroll to Top of Div Element Example
- Angular Material Textarea Tutorial