Home > front end >  angular ngForm is not working on submittion
angular ngForm is not working on submittion

Time:08-13

Hi guys I am trying to implement ngForm but its not working.

html code: this is my html page

<form #loginForm="ngForm" (ngSubmit)="userLogin(loginForm.value)">
<input type="text" placeholder="Enter Name" name="name" ngModal>
<br> 
<br>
<button type="submit">Login/buttong</button>
</form>

ts code: ts page code is here

userLogin(form: NgForm) { console.log(form); }

module.ts code

import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';  

@NgModule({
  declarations: [AppComponent, DatatableTestComponent],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    ReactiveFormsModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule { }

while submitting the form it doesn't access its value, didn't understand the issue bcoz I have followed the steps from tutorial video

CodePudding user response:

Confirm that you have added FormsModule in the app.module.ts

CodePudding user response:

Exactly in your example you wrote ngMod(a)l instead of ngMod(e)l.

Also, as @CarlitosJan noticed, you don't need ReactiveFormsModule for your form implementation.

  • Related