import { Attribute , Directive , ElementRef , EventEmitter , Inject , OnDestroy , Output , } from '@angular/core' ; import { MUTATION_OBSERVER_INIT } from '../tokens/mutation-observer-init' ; import { mutationObserverInitFactory } from '../utils/mutation-observer-init-factory' ; @ Directive ( { selector : '[waMutationObserver]' , exportAs : 'MutationObserver' , providers : [ { provide : MUTATION_OBSERVER_INIT , deps : [ ElementRef ] , useFactory : mutationObserverInitFactory , } , ] , } ) export class MutationObserverDirective extends MutationObserver implements OnDestroy { @ Output ( ) readonly waMutationObserver = new EventEmitter < MutationRecord [ ] > ( ) ; constructor ( @ Inject ( ElementRef ) { nativeElement } , @ Inject ( MUTATION_OBSERVER_INIT ) config , @ Attribute ( 'attributeFilter' ) _1 , @ Attribute ( 'attributeOldValue' ) _2 , @ Attribute ( 'attributes' ) _3 , @ Attribute ( 'characterData' ) _4 , @ Attribute ( 'characterDataOldValue' ) _5 , @ Attribute ( 'childList' ) _6 , @ Attribute ( 'subtree' ) _7 ) { super ( records => { this . waMutationObserver . emit ( records ) ; } ) ; this . observe ( nativeElement , config ) ; } ngOnDestroy ( ) { this . disconnect ( ) ; } }