Error "Property 'value' does not exist on type 'EventTarget'" in Angular and TypeScript
Hi everyone! I'm new to Angular and TypeScript, and I've been struggling with an error for several hours. I have a simple component with an input, and I want to log the text to the console as I type. Here's my code:
```typescript
import { Component } from '@angular/core';
@Component({
selector: 'app-my-component',
template: `
`
})
export class MyComponent {
onInput(event: Event) {
console.log(event.target.value); // Error here!
}
}
```
TypeScript throws an error: "Property 'value' does not exist on type 'EventTarget'". I've read that this is related to types, but I don't understand how to fix it. Why doesn't event.target.value work? In JavaScript, this is a normal property for an input. How do I correctly get the value from the input field? I've tr
No answers yet.
Log in to leave an answer