Skip to content Skip to sidebar Skip to footer

How To Trigger Click On An HTML File Element From A Component ? (Angular 2)

I am very new to Angular 2 the question is How to trigger click on an HTML file element from a component? rankingFilter() { this.RepsloaderShow = true; this.reps = [];

Solution 1:

For dispatching from the host element

constructor(private elRef:ElementRef, private renderer:Renderer) {}

For dispatching from an element inside the template

<some-elem #target></some-element>
@ViewChild('target') elRef:ElementRef;

And then dispatch the event:

  ...
    this.renderer.invokeElementMethod(this.elRef.nativeElement, 
        'dispatchEvent', 
        [new MouseEvent('click', { bubbles: true, cancelable: true })]);

Post a Comment for "How To Trigger Click On An HTML File Element From A Component ? (Angular 2)"