问题描述
@HostListener OnClick在firefox中不起作用
我试过onClick,onclick和onGlobalClick。他们都在铬工作,但在Firefox中没有人。
这是mY代码:
$ p $ 构造函数(private elRef:ElementRef,private renderer:Renderer2){}
@Output()offClick = new EventEmitter();
$ b $ @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);
$ b $ p $请帮忙
@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);
}
}
@HostListener OnClick does not working in firefoxI 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);
}
}
Please help
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);
}
}
这篇关于@HostListener OnClick不能在Firefox中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!