html 型别'Event'无法指派给型别'string'

sc4hvdpw  于 2022-12-09  发布在  其他
关注(0)|答案(2)|浏览(163)

我是新的Angular ,我是按照这个英雄教程时,我偶然发现这个错误:

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

我重现了错误here

iezvtpos

iezvtpos1#

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 {}
pes8fvy9

pes8fvy92#

如果您正在使用独立组件(这是Angular 14的新特征),则必须导入
组件Ts文件中的窗体模块

import { Component, OnInit } from "@angular/core";
import  {CommonModule} from '@angular/common'

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

@Component({
    standalone:true,
    selector: 'test',
    templateUrl:'./test.components.html',
    styleUrls : ['./test.components.css'],
    imports:[CommonModule,**FormsModule **]
})

相关问题