1

I'm trying to pass the click text into a variable on a click event. Here's the code I have at the moment:

<th (click)="sortedColumn = clickValue">Ask Price</th>

So, when a user clicks on the table header, I'd like for it to store the table header value "Ask Price" in the sortedColumn variable.

2 Answers 2

3

You can try two options:

  • using template reference variable

    <th (click)="sortedColumn = ref.textContent" #ref>Ask Price</th>
                                                 ^^^^
    
  • using $event

    <th (click)="sortedColumn = $any($event.target).textContent">Ask Price</th>
    
Sign up to request clarification or add additional context in comments.

Comments

2

I can't comment yet but as an appendix to the answer above:

I would also pass the value to a function defined in your .ts Component and assign the value there to the property.

html:

<th (click)="onClickHeader($any($event.target).textContent)">Ask Price</th>

ts:

public onClickHeader(value: string): void { this.sortedColumn = value; }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.