如何通过Typescript(Angular2)检测页面上的任何位置的单击 [英] How to detect click anywhere on the page by Typescript (Angular2)
本文介绍了如何通过Typescript(Angular2)检测页面上的任何位置的单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过Typescript检测页面上任何位置的点击?在AngularJS 2中
How to detect click anywhere on the page by Typescript? in AngularJS 2
推荐答案
您可以将 HostListener
的范围设置为文档.
You can scope a HostListener
to the document.
import { Component, HostListener } from '@angular/core'
class MyComponent {
@HostListener('document:click', ['$event'])
documentClick(event: MouseEvent) {
// your click logic
}
}
这篇关于如何通过Typescript(Angular2)检测页面上的任何位置的单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文