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.
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 {}
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 **]
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With