You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
782 B
31 lines
782 B
import {Directive, ElementRef, EventEmitter, OnDestroy, Output} from '@angular/core';
|
|
|
|
@Directive({
|
|
selector: '[appDomChange]'
|
|
})
|
|
export class DomChangeDirective implements OnDestroy {
|
|
private changes: MutationObserver;
|
|
|
|
@Output()
|
|
public domChange = new EventEmitter();
|
|
|
|
constructor(private elementRef: ElementRef) {
|
|
const element = this.elementRef.nativeElement;
|
|
|
|
this.changes = new MutationObserver((mutations) => {
|
|
mutations.forEach(mutation => this.domChange.emit(mutation));
|
|
});
|
|
|
|
this.changes.observe(element, {
|
|
attributes: true,
|
|
childList: true,
|
|
characterData: true,
|
|
subtree: true,
|
|
});
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.changes.disconnect();
|
|
}
|
|
}
|