在Angular2的任何位置检测鼠标单击 [英] Detect mouse click anywhere Angular2
本文介绍了在Angular2的任何位置检测鼠标单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是打字稿和angular 2的初学者,我的代码有错误!您能帮我解决这个问题吗?
I'm beginner in typescript and angular 2, I have error in my code! Would you please help me to fix this?
import { Component, HostListener } from '@angular/core'
export class TooltipComponent {
public show: boolean = false;
@HostListener('document:click',['$event'])
documentClick(event: MouseEvent) {
this.show = false;
}
showTooltip() {
this.show = true;
this.documentClick('????');
}
}
推荐答案
@HostListener('document:click', ['$event'])
public documentClick(event: Event): void {
//doSomething () --> Your logic when there is a document click
}
问题尚不清楚,但是单击文档后,上面的代码将被触发
Question is bit unclear, But the code above would get fired when there is a document click
这篇关于在Angular2的任何位置检测鼠标单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文