失败:模板解析错误:没有将“ exportAs”设置为“ ngForm”的指令Angular 6

时间:2019-02-01 14:46:36

标签: angular typescript angular6

能否请您帮我,我知道您可能多次遇到此错误,但是我白费了一切! 这是我的表格:

<div class="row">
  <h1>Ajouter métier</h1>
  <div class="col-sm-8 col-sm-offset-2">
  <form (ngSubmit)="onSubmit(f)" #f="ngForm" >
    <div class="form-group">
      <label for="name">
        Intitulé de métier
      </label>
      <input type="text" id="name" class="form-control" name="name" #name="ngModel" ngModel required>
    </div>
    <button class="btn btn-primary" type="submit" [disabled]="f.invalid">Valider</button>
  </form>
  </div>
</div>

我的module.ts:

@NgModule({
  declarations: [
    AppComponent,
    ListMetierComponent,
    AddMetierComponent
  ],
  imports: [
    // NgbModule.forRoot(),
    NgBoostedModule,
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    HttpClientModule,
    RouterModule.forRoot(appRoutes)
  ],
  providers: [
    MetierService,
    HttpClientModule,
    HttpClient
  ],
  bootstrap: [AppComponent]
})

并用茉莉花/业力测试我的代码,我一直都收到这个错误!!

Failed: Template parse errors:
There is no directive with "exportAs" set to "ngForm" ("  <h1>Ajouter métier</h1>
  <div class="col-sm-8 col-sm-offset-2">
  <form (ngSubmit)="onSubmit(f)" [ERROR ->]#f="ngForm" >
    <div class="form-group">
      <label for="name">
"): ng:///DynamicTestModule/AddMetierComponent.html@3:33
There is no directive with "exportAs" set to "ngModel" ("titulé de métier
      </label>
      <input type="text" id="name" class="form-control" name="name" [ERROR ->]#name="ngModel" ngModel required>
    </div>
    <button class="btn btn-primary" type="submit" [disab"): ng:///DynamicTestModule/AddMetierComponent.html@8:68

非常感谢

0 个答案:

没有答案