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

前端 未结 22 1449
轻奢々
轻奢々 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:49

    I had the same issue and solved it by updating all dependencies (package.json) with the following command npm update -D && npm update -S

    As @Günter Zöchbauer pointed out, make sure to include the FormsModule first.

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

    In my case I had to remove the ngNoForm attribute from my <form> tag.

    If you you want to import FormsModule in your application but want to skip a specific form, you can use the ngNoForm directive which will prevent ngForm from being added to the form

    Reference: https://www.techiediaries.com/angular-ngform-ngnoform-template-reference-variable/

    0 讨论(0)
  • 2020-12-04 09:52
    import { FormsModule }   from '@angular/forms';
    
    @NgModule({
      imports: [
                 BrowserModule,
    
                 FormsModule      //<----------make sure you have added this.
               ],
      ....
    })
    
    0 讨论(0)
  • 2020-12-04 09:53

    You should terminate app with ctrl+c and re run it with ng serve, if you did not include FormsModule into you app.module file imports array, and then added it later, angular does not know it, it does not re-scan modules, you should restart app so angular could see that new module is included, after what it will included all features of template drive approach

    0 讨论(0)
提交回复
热议问题