Error NG8003: No directive found with exportAs 'ngForm'

Viewed 4943

I have just updated to angular 9! and suddenly I got this exception: Error occurs in the template of *, error NG8003: No directive found with exportAs 'ngForm'

Here is the template:

 <form (ngSubmit)="onLogin(frm.value)" #frm="ngForm" style="margin:0 auto;"> //All of these was working fine before the update

I also imported FormsModule, ReactiveFormsModule, CommonModule in app.module.ts:

imports: [
BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
HttpClientModule,
FormsModule, 
ReactiveFormsModule,
CommonModule,

Note, I am using Visual Studio angular template.

Thank you for help.

2 Answers

You will have to add the ngForm directive to the form:

<form (ngSubmit)="onLogin(frm.value)" ngForm #frm style="margin:0 auto;">

A bit of knowledge :

the libraries we are going to use in our web app should be imported and should be added imported array of the parent module .

In abv eg . 'Form module' should be imported in app.module.ts file and should be added to the 'imports:[]' array of app.module.ts to make it available for its child components.

this should be done cause once you imported the library in parent(eg. m_name.module.ts ) it'll allow that library to its child components(eg. C_name.component.ts)

this is how the Mr. Angular work . :D:D

Related