Skip to content

Instantly share code, notes, and snippets.

@nitayneeman
Last active September 11, 2017 16:02
Show Gist options
  • Save nitayneeman/293d73c42e5b2929ae2696efe469b576 to your computer and use it in GitHub Desktop.
Save nitayneeman/293d73c42e5b2929ae2696efe469b576 to your computer and use it in GitHub Desktop.
@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