由于它不是'input'的已知属性,因此无法绑定到'ngModel'吗?

时间:2020-02-21 16:56:08

标签: angular angular6 angular8

完整代码是:

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

应用程序模块为:

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

出什么问题了,为什么它对我不起作用?

2 个答案:

答案 0 :(得分:1)

尝试一下:

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

将此模块添加到您的:

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

答案 1 :(得分:1)

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