Open In App

Angular FormsModule Directive

In this article, we are going to see what is FormsModule in Angular 10 and how to use it.

The FormsModule is used to make all the necessary imports for form implementation.



Syntax:

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

Approach: 



 

Example 1:




import { NgModule } from '@angular/core';
  
// Importing forms module
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 { }




<form #gfgform = "ngForm">
  {{ gfgform.value | json }}
  <br>
  <br>
  Name: <input type="text" name = 'name' ngModel>
  Roll: <input type="text" name = 'roll' ngModel>
</form>

Output:

Reference: https://angular.io/api/forms/FormsModule


Article Tags :