控制台中的NgModel错误

时间:2017-08-08 21:34:51

标签: angular angular-ngmodel

我正在尝试从此组件中记录ngModel,以便我可以将其检查用于教育目的

<input ngModel name="firstName" id="firstName" type="text" #firstname="ngModel" (change)="log(firstname)" class="form-control">

但我收到此错误,我似乎无法诊断错误。

Uncaught Error: Template parse errors: There is no directive with "exportAs" set to "ngModel" ("">First Name</label>
<input [(ngModel)]="firstName" name="firstName" id="firstName" type="text" 
[ERROR ->]#firstname="ngModel" (change)="log(firstname)" class="form-control 
</div><div class="form-grou"): ng:///AppModule/ContactFormComponent.html@3:79 Can't bind to 'ngModel' 
since it isn't a known property of 

1 个答案:

答案 0 :(得分:1)

  1. 复制您添加的模块代码
  2. 删除模块并确保项目使用(ng serve)成功编译。
  3. 重新生成模块并放回代码。
  4. 在app.modile.ts
  5. 中添加FormsModule
    @NgModule({
          declarations: [
            AppComponent,
            ContactFormComponent
          ],
          imports: [
            BrowserModule,
            FormsModule
          ],