无法绑定到 'ngModel',因为它不是 'input' 的已知 属性?

Can't bind to 'ngModel' since it isn't a known property of 'input'?

完整代码为:

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

app.module 是:

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

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

试试这个:

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

将此模块添加到您的:

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

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

中导入 FormsModule 和 NgModule