UNPKG

bia-framework

Version:

Bia Framework to work with angular 2

40 lines (32 loc) 754 B
/** * Created by jd on 28/04/2016. */ import {Directive, Input, OnInit, OnDestroy, HostListener} from '@angular/core'; @Directive({ selector: '[offClick]' }) export class OffClick implements OnInit, OnDestroy { @Input('offClick') offClickHandler; //not propagate click event on host component @HostListener('click', ['$event']) private onClick= ($event) => { $event.stopPropagation(); }; constructor() { } ngOnInit() { setTimeout(() => { document.addEventListener('click', this.offClickHandler); }, 0); } ngOnDestroy() { document.removeEventListener('click', this.offClickHandler); } }