@@ -16,6 +16,7 @@ import {
16
16
OnDestroy ,
17
17
AfterContentInit ,
18
18
Injectable ,
19
+ NgZone ,
19
20
} from '@angular/core' ;
20
21
import { Subject } from 'rxjs/Subject' ;
21
22
import { RxChain , debounceTime } from '@angular/cdk/rxjs' ;
@@ -52,19 +53,24 @@ export class ObserveContent implements AfterContentInit, OnDestroy {
52
53
53
54
constructor (
54
55
private _mutationObserverFactory : MdMutationObserverFactory ,
55
- private _elementRef : ElementRef ) { }
56
+ private _elementRef : ElementRef ,
57
+ private _ngZone : NgZone ) { }
56
58
57
59
ngAfterContentInit ( ) {
58
60
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
+ } ) ;
62
66
} else {
63
67
this . _debouncer . subscribe ( mutations => this . event . emit ( mutations ) ) ;
64
68
}
65
69
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
+ } ) ;
68
74
} ) ;
69
75
70
76
if ( this . _observer ) {
@@ -79,8 +85,9 @@ export class ObserveContent implements AfterContentInit, OnDestroy {
79
85
ngOnDestroy ( ) {
80
86
if ( this . _observer ) {
81
87
this . _observer . disconnect ( ) ;
82
- this . _debouncer . complete ( ) ;
83
88
}
89
+
90
+ this . _debouncer . complete ( ) ;
84
91
}
85
92
}
86
93
0 commit comments