I would suggest using rxjs.
Add a global `clickSubscription: Subscription` in your component; then in `ngOnInit` you can do:
ngOnInit(): void {
this.clickSubscription = fromEvent(document, 'click').subscribe(event => {
console.log(event);
})
}
and in `ngOnDestroy`:
ngOnDestroy(): void {
this.clickSubscription.unsubscribe();
}
I would suggest using rxjs:
import { fromEvent, Subscription } from 'rxjs';
Add a global `clickSubscription: Subscription` in your component; then in `ngOnInit` you can do:
ngOnInit(): void {
this.clickSubscription = fromEvent(document, 'click').subscribe(event => {
console.log(event);
})
}
and in `ngOnDestroy`:
ngOnDestroy(): void {
this.clickSubscription.unsubscribe();
}