Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm new to angular and I was following this hero tutorial when I stumbled upon this error:

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

I reproduced the error here.

like image 324
Rasmus Avatar asked Oct 30 '25 21:10

Rasmus


2 Answers

You are missing the FormsModule import in your AppModule.

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 {}
like image 173
Ismail Dinar Avatar answered Nov 02 '25 10:11

Ismail Dinar


if you are working with standalone Components (which is angular 14 new feature ) then you have to import

form module in your components Ts file

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 **]
})
like image 36
Mali Gautam H Avatar answered Nov 02 '25 12:11

Mali Gautam H