In this article, we are going to see what is NgForm in Angular 10 and how to use it. NgForm is used to create a top-level form group Instance, and it binds the form to the given form value.
Syntax:
<form #FormName = "ngForm"> </form>
NgModule: Module used by NgForm is:
Selectors:
Approach:
- Create the Angular app to be used
- In app.module.ts import FormsModule.
- In app.component.html make a form and store its value in ngForm variable and show its value in a JSON form.
- Serve the angular app using ng serve to see the output.
Example 1:
app.module.ts
import { NgModule } from '@angular/core' ;
import { FormsModule } from '@angular/forms' ;
import { BrowserModule } from '@angular/platform-browser' ;
import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
import { AppComponent } from './app.component' ;
@NgModule({
bootstrap: [
AppComponent
],
declarations: [
AppComponent
],
imports: [
FormsModule,
BrowserModule,
BrowserAnimationsModule,
]
})
export class AppModule { }
|
app.component.html
< form # gfgform = "ngForm" >
{{ gfgform.value | json }}
< br >
< br >
Name: < input type = "text" name = 'name' ngModel>
Email: < input type = "email" name = 'email' ngModel>
</ form >
|
Output:

Reference: https://angular.io/api/forms/NgForm
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
24 May, 2021
Like Article
Save Article