error TS2339: Property 'value' does not exist on type
I got the above error while using the following codes
Code in HTML
<input type="text" (input)="title = $event.target.value" />
Can please anyone guide me also providing me with the solution?
CodePudding user response:
I think you can simply write it like this,
in your component make an event handler function like given below,
onInput(e: any) {
this.title = e.target.value;
}
And your HTML file can look like this,
<input type="text" (input)="onInput($event)" />
CodePudding user response:
As @LukaszGawrys already mentioned in the comment, you can use Angular two way data binding [(ngModel)]
syntax as:
<input type="text" [(ngModel)]="title" name="title" />
For ngModel
to work, you would need to import FormsModule
as:
@NgModule({
declarations: [ ... ],
imports: [
...
FormsModule
]
})
export class AppModule { }