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