I keep getting this error while using TypeScript\'s Angular2-forms framework:
There is no
directive
with \"exportAs\" set to \"ngForm
This error also occurs if you are trying to write a unit test case in angular using jasmine.
The basic concept of this error is to import FormsModule
. Thus, in the file for unit tests, we add imports Section and place FormsModule in that file under
TestBed.configureTestingModule
For eg:
TestBed.configureTestingModule({
declarations: [ XYZComponent ],
**imports: [FormsModule]**,
}).compileComponents();
In my case, I forgot to add my component in the Declaration array of app.module.ts, and voila! the issue was fixed.
In addition to import the form module in login component ts file you need to import NgForm also.
import { NgForm } from '@angular/forms';
This resolved my issue
I faced this issue, but none of the answers here worked for me. I googled and found that FormsModule not shared with Feature Modules
So If your form is in a featured module, then you have to import and add the FromsModule
there.
Please ref: https://github.com/angular/angular/issues/11365
I know this is a Old post, but i would like to share my solution. I have added "ReactiveFormsModule" in imports[] array to resolve this error
Error: There is no directive with "exportAs" set to "ngForm" ("
Fix:
module.ts
import {FormsModule, ReactiveFormsModule} from '@angular/forms'
imports: [
BrowserModule,
FormsModule ,
ReactiveFormsModule
],
Just import the correct module,
"FormsModule"
import { FormsModule } from "@angular/forms";
@NgModule({
imports: [
BrowserModule,
FormsModule //<---.
],
....
})