Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

416
Views
How to trigger a click event on child element got using querySelector on native element in angular2/angular4

I tried the code below but didn't work. I'm using Angular4. I want to trigger a click event if the input of handle click is not less than 3.

import { Component, OnInit, ElementRef } from '@angular/core';

@Component({
    selector: 'box-frame',
    template: `
            <div>
              <div (click)="handleClick(i)" id="box{{i}}" *ngFor="let i of array"></div>   
            </div>
          `
})
export class BoxFrameComponent implements OnInit {
    array: any = [1, 2, 3, 4, 5, 6];
    constructor(private eleRef: ElementRef) { };
    ngOnInIt() {
    };
    handleClick(n: number) {
        if (n < 3) {
            console.log(n);
        } else {
            let smallBox = this.eleRef.nativeElement.querySelector('#box' + n - 1);
            //this didn't work
            smallBox.dispatchEvent('click');
        }

    };
};
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

smallBox.dispatchEvent(new CustomEvent('click'));
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!