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

424
Views
Cómo activar un evento de clic en un elemento secundario obtenido usando querySelector en un elemento nativo en angular2/angular4

Probé el siguiente código pero no funcionó. Estoy usando Angular4. Quiero activar un evento de clic si la entrada del clic del controlador no es inferior a 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!