Issue
Browser shows failed to compile. Please help
Error : Property 'value' does not exist on type 'EventTarget'
HTML code :
<div>
<label>Enter Length</label>
<input (input)="onChangeLength($event.target.value)" />
</div>
Typescript code
onChangeLength(value: string){
const parsedValue = parseInt(value);
if(!isNaN(parsedValue)){
this.lenght = parsedValue;
}
}
Solution
Angular docs seem to suggest the way you are doing it is right:
You could try passing $event
to the function and casting like they do:
onChangeLength(event: Event): string {
const inputChangeValue = (event.target as HTMLInputElement).value;
// ...
}
Answered By - Robert Rendell
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.