@@ -16,6 +16,7 @@ import {
1616 OnDestroy ,
1717 AfterContentInit ,
1818 Injectable ,
19+ NgZone ,
1920} from '@angular/core' ;
2021import { Subject } from 'rxjs/Subject' ;
2122import { RxChain , debounceTime } from '@angular/cdk/rxjs' ;
@@ -52,19 +53,24 @@ export class ObserveContent implements AfterContentInit, OnDestroy {
5253
5354 constructor (
5455 private _mutationObserverFactory : MdMutationObserverFactory ,
55- private _elementRef : ElementRef ) { }
56+ private _elementRef : ElementRef ,
57+ private _ngZone : NgZone ) { }
5658
5759 ngAfterContentInit ( ) {
5860 if ( this . debounce > 0 ) {
59- RxChain . from ( this . _debouncer )
60- . call ( debounceTime , this . debounce )
61- . subscribe ( ( mutations : MutationRecord [ ] ) => this . event . emit ( mutations ) ) ;
61+ this . _ngZone . runOutsideAngular ( ( ) => {
62+ RxChain . from ( this . _debouncer )
63+ . call ( debounceTime , this . debounce )
64+ . subscribe ( ( mutations : MutationRecord [ ] ) => this . event . emit ( mutations ) ) ;
65+ } ) ;
6266 } else {
6367 this . _debouncer . subscribe ( mutations => this . event . emit ( mutations ) ) ;
6468 }
6569
66- this . _observer = this . _mutationObserverFactory . create ( ( mutations : MutationRecord [ ] ) => {
67- this . _debouncer . next ( mutations ) ;
70+ this . _observer = this . _ngZone . runOutsideAngular ( ( ) => {
71+ return this . _mutationObserverFactory . create ( ( mutations : MutationRecord [ ] ) => {
72+ this . _debouncer . next ( mutations ) ;
73+ } ) ;
6874 } ) ;
6975
7076 if ( this . _observer ) {
@@ -79,8 +85,9 @@ export class ObserveContent implements AfterContentInit, OnDestroy {
7985 ngOnDestroy ( ) {
8086 if ( this . _observer ) {
8187 this . _observer . disconnect ( ) ;
82- this . _debouncer . complete ( ) ;
8388 }
89+
90+ this . _debouncer . complete ( ) ;
8491 }
8592}
8693
0 commit comments