TypeScript-'s Angular Framework Error - “There is no directive with exportAs set to ngForm”

前端 未结 22 1450
轻奢々
轻奢々 2020-12-04 09:18

I keep getting this error while using TypeScript\'s Angular2-forms framework:

There is no directive with \"exportAs\" set to \"ngForm

相关标签:
22条回答
  • 2020-12-04 09:40

    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();
    
    0 讨论(0)
  • 2020-12-04 09:40

    In my case, I forgot to add my component in the Declaration array of app.module.ts, and voila! the issue was fixed.

    0 讨论(0)
  • 2020-12-04 09:46

    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

    0 讨论(0)
  • 2020-12-04 09:46

    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

    0 讨论(0)
  • 2020-12-04 09:49

    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
      ],
    
    0 讨论(0)
  • 2020-12-04 09:49

    Just import the correct module,

    "FormsModule"

    import { FormsModule } from "@angular/forms";
    
    @NgModule({
      imports: [
        BrowserModule,
        FormsModule //<---.
      ],
      ....
    })
    
    0 讨论(0)
提交回复
热议问题