【问题标题】:I am getting error in binding ngModel in input我在输入中绑定 ngModel 时出错
【发布时间】:2018-07-18 14:26:14
【问题描述】:

在将 ngModel 绑定到输入时,我发现以下错误 -

Can't bind to 'ngModel' since it isn't a known property of 'input'. ("<div>
<span> Select : </span>
<input type="radio" name="options" value="all" [ERROR ->][(ngModel)]="SelectRadioButtonValue" (change)="onRadioButtonSelectionChanged()"  />
<span> {{"All: " "): ng:///AppModule/EmpCountComponent.html@2:47
Can't bind to 'ngModel' since it isn't a known property of 'input'. (">
<span> {{"male: " + '(' + male + ')' }} </span>
<input type="radio" name="options" value="female" [ERROR ->][(ngModel)]="SelectRadioButtonValue"   (change)="onRadioButtonSelectionChanged()" />
<span> {{"Female"): ng:///AppModule/EmpCountComponent.html@6:50

【问题讨论】:

标签: angular angular-ngmodel ngmodel


【解决方案1】:

要使用[(ngModel)],您应该将FormsModule 导入您的AppModule

import { FormsModule } from '@angular/forms';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-13
    • 2017-08-16
    • 2020-09-30
    • 2017-01-13
    • 2021-07-25
    • 2018-06-07
    • 1970-01-01
    相关资源
    最近更新 更多