Angular: error trying to manipulate input value - Property 'value' does not exist on type 'Element

Asked

Viewed 315 times

0

I’m having trouble trying to get the value of an input to clear it, the code is in a script . ts (used in Angular 7), code below:

document.querySelector('.input').value = "";

Error while compiling code

error TS2339: Property 'value' does not exist on type 'Element'

Is something missing? Because I did tests using the console and everything went right.

  • 1

    The best would be to take from your Ngmodel or your Reactiveforms depending on which you are using. This taking input value through Dom was old jquery practice and is not recommended mainly with angular.

  • I’ll look into Ngmodel and Reactiveforms, thank you!

1 answer

0


The problem was of the type that could not be Element, I was able to solve with the code below, converting from Element to Input:

(document.querySelector('.input') as HTMLInputElement).value = "";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.