首页 > 解决方案 > 类型“事件”不可分配给类型“字符串”

问题描述

我是Angular 的新手,当我偶然发现这个错误时,我正在关注这个英雄教程:

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

我在这里重现了错误。

标签: javascripthtmlangulartypescript

解决方案


您的 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 {}

推荐阅读