5

How to detect click anywhere on the page by Typescript? in AngularJS 2

Nasim Mokhtar
  • 61
  • 1
  • 1
  • 5

1 Answers1

18

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
    }
}
adharris
  • 3,591
  • 1
  • 21
  • 18