import { ElementRef , Inject , Injectable } from '@angular/core' ; import { Observable } from 'rxjs' ; import { MUTATION_OBSERVER_INIT } from '../tokens/mutation-observer-init' ; @ Injectable ( ) export class MutationObserverService extends Observable < ReadonlyArray < MutationRecord > > { constructor ( @ Inject ( ElementRef ) { nativeElement } , @ Inject ( MUTATION_OBSERVER_INIT ) config ) { super ( subscriber => { const observer = new MutationObserver ( records => { subscriber . next ( records ) ; } ) ; observer . observe ( nativeElement , config ) ; return ( ) => { observer . disconnect ( ) ; } ; } ) ; } }