Skip to content

Instantly share code, notes, and snippets.

@hiepxanh
Last active August 19, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiepxanh/c7a174e89d06fcdb11bef2c5539f530e to your computer and use it in GitHub Desktop.
Save hiepxanh/c7a174e89d06fcdb11bef2c5539f530e to your computer and use it in GitHub Desktop.
// from here:
// @HostListener('document:click', ['$event'])
// clickout(event) {
// console.log("target?",event.target);
// if(this.eRef.nativeElement.contains(event.target)) {
// console.log("clicked inside",event);
// } else {
// console.log("clicked outside",event);
// }
// }
// upgrade 1:
// @ViewChild('confirm') confirm: ElementRef;
// @ViewChild('pending') pending: ElementRef;
// @ViewChild('statistic') statistic: ElementRef;
// @ViewChild('notification') notification: ElementRef;
// @HostListener('document:click', ['$event'])
// clickout(event) {
// let result =
// event.path.includes(this.confirm.nativeElement) ||
// event.path.includes(this.pending.nativeElement) ||
// event.path.includes(this.statistic.nativeElement) ||
// event.path.includes(this.notification.nativeElement)
// console.log('includes 1 in 4 buttons?',result)
// if(result) {
// console.log("clicked inside",event);
// } else {
// console.log("clicked outside",event);
// }
// }
// upgrarde 2:
@ViewChild('confirm') confirm: ElementRef;
@ViewChild('pending') pending: ElementRef;
@ViewChild('statistic') statistic: ElementRef;
@ViewChild('notification') notification: ElementRef;
@HostListener('document:click', ['$event'])
clickout(event) {
if (event.path.includes(this.confirm.nativeElement)) this.toogleItem(this.status.confirm)
else if (event.path.includes(this.pending.nativeElement)) this.toogleItem(this.status.pending)
else if (event.path.includes(this.statistic.nativeElement)) this.toogleItem(this.status.statistic)
else if (event.path.includes(this.notification.nativeElement)) this.toogleItem(this.status.notification)
else this.toogleItem({name:''})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment