Last active
September 11, 2017 16:02
-
-
Save nitayneeman/293d73c42e5b2929ae2696efe469b576 to your computer and use it in GitHub Desktop.
This file contains 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
@Directive({ | |
selector: '[domChange]' | |
}) | |
export class DomChangeDirective { | |
private changes: MutationObserver; | |
@Output() | |
public domChange = new EventEmitter(); | |
constructor(private elementRef: ElementRef) { | |
const element = this.elementRef.nativeElement; | |
this.changes = new MutationObserver((mutations: MutationRecord[]) => { | |
mutations.forEach((mutation: MutationRecord) => this.domChange.emit(mutation)); | |
} | |
); | |
this.changes.observe(element, { | |
attributes: true, | |
childList: true, | |
characterData: true | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment