1

I have a button that refreshes data.

I would like to generate 10 clicks on this button.

<data-box class="market" [data]="data">
  <h2>Data</h2>
  <img class="refresh" src="assets/img/refresh.png" (click)="getMarketData()"/>
</data-box>

I want a function that clicks the button (not call the function that is triggered by the button)

3

1 Answer 1

2
<img class="refresh" src="assets/img/refresh.png" #Refresh (click)="getMarketData()" />

Add #Refresh on your element, and then reference it using ViewChild

@ViewChild('Refresh') myDiv: ElementRef<HTMLElement>;

  triggerFalseClick() {
    let el: HTMLElement = this.myDiv.nativeElement;
    el.click();
}

triggerFalseClick will click your button, you can call it as many times as you want.

Sign up to request clarification or add additional context in comments.

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.