首页 > 解决方案 > 不能绑定到“ngModel”,因为它不是“输入”的已知属性?

问题描述

完整代码是:

 <input #inputSearch tabindex="0" [(ngModel)]="searchValue" (keydown.enter)="searchByClick()" type="text">

app.module 是:

@NgModule({
declarations: [],
 imports: [
    CommonModule,
    SharedModule,
    BrowserModule,
    AppRoutingModule
  ]
)}
export class AppModule {}

怎么了,为什么它对我不起作用?

标签: angularangular6angular8

解决方案


import { FormsModule } from '@angular/forms'; import { NgModule } from "@angular/core";在 app.module.ts 中导入 FormsModule 和 NgModule


推荐阅读