Property 'value' does not exist on type 'HTMLElement' for Textarea - Angular

Viewed 31526

Using Angular 4 (typescript), I have the below HTML code:

 <div *ngIf="dataService.selected_markers.length == 0" id="tsnPasteContainer">
      <form style="width: 100%; height: 100%">
        <textarea id="tsn_list" style="width: 100%; height: 100%" type="text" name="tsn_list" placeholder="e.g. 2001311,2425302,2153542,2435974"></textarea>
      </form>
    </div>

I am trying to get the data that the user is typing into the textarea using:

public parseTSNs(){
    let tsnString = document.getElementById("tsn_list").value;
    console.log("User inputted string: " + tsnString);
}

This function is called by a button.

The code is not compiling due to:

Property 'value' does not exist on type 'HTMLElement'

This should be a simple function. What am I doing wrong? W3schools "getting values from textarea" shows '.value' as the required function!

4 Answers

I had faced a similar issue while setting the value of a cell in the table.

I was adding the data as follows:

document.getElementById("table_id").rows[0].cells[0].innerHTML = "data_to_be_added";

And I was getting the following error:

error TS2339: Property 'rows' does not exist on type 'HTMLElement'

Property 'cells' does not exist on type 'HTMLElement'

So I added the following tag and the ERROR got resolved.

(document.getElementById("table_id") as any).rows[0].cells[0].innerHTML = "data_to_be_added";

Here, you are expicitly changing the type of the variable as any.

Related