Last active
August 25, 2017 12:06
-
-
Save NetanelBasal/a7b071e86777fd385d1cf9bbd97161f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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