@HostListener OnClick does not work in firefox. I tried onClick, onclick and onGlobalClick. They all work in chrome but no one in firefox. Here is my code:
constructor(private elRef: ElementRef, private renderer: Renderer2) { }
@Output() offClick = new EventEmitter();
@HostListener('document:click', ['$event.path'])
public onGlobalClick(targetElementPath: Array<any>) {
const elementRefInPath = targetElementPath.find(e => e === this.elRef.nativeElement);
if (!elementRefInPath) {
this.offClick.emit(1);
}
}
Here is what I tested in all browsers and it works:
@HostListener('document:click', ['$event', '$event.target'])
onClick(event: MouseEvent, targetElement: HTMLElement): void {
if (!targetElement) {
return;
}
const clickedInside = this.elementRef.nativeElement.contains(targetElement);
if (!clickedInside) {
this.clickOutside.emit(event);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With