Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Last active August 25, 2017 12:06
Show Gist options
  • Save NetanelBasal/a7b071e86777fd385d1cf9bbd97161f3 to your computer and use it in GitHub Desktop.
Save NetanelBasal/a7b071e86777fd385d1cf9bbd97161f3 to your computer and use it in GitHub Desktop.
import { Directive, Output, EventEmitter, Renderer2, ElementRef } from '@angular/core';
@Directive({
selector: '[click.stop]'
})
export class StopPropagationDirective {
@Output("click.stop") stopPropEvent = new EventEmitter();
unsubscribe;
constructor( private renderer : Renderer2, private element : ElementRef ) {
}
ngOnInit() {
this.unsubscribe = this.renderer.listen(this.element.nativeElement, "click", event => {
event.stopPropagation();
this.stopPropEvent.emit(event);
});
}
ngOnDestroy() {
this.unsubscribe();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment