“事件”类型不能分配给“字符串”类型

时间:2021-03-14 14:31:44

标签: javascript html angular typescript

我是 angular 的新手,当我偶然发现此错误时,我正在关注此 hero tutorial

Type 'Event' is not assignable to type 'string'

我重现了错误 here

1 个答案:

答案 0 :(得分:2)

您的 AppModule 中缺少 FormsModule 导入。

import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { AppComponent } from "./app.component";
import { HeroComponent } from "./hero/hero.component";

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