Initial editor functionality and data bindings
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
9
src/app/directives/directives.module.ts
Normal file
9
src/app/directives/directives.module.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {DomChangeDirective} from './dom-change.directive';
|
||||
|
||||
@NgModule({
|
||||
imports: [],
|
||||
exports: [DomChangeDirective],
|
||||
declarations: [DomChangeDirective],
|
||||
})
|
||||
export class DirectivesModule {}
|
||||
30
src/app/directives/dom-change.directive.ts
Normal file
30
src/app/directives/dom-change.directive.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user