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');
}
};
};