File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
15
15
Injectable ,
16
16
Input ,
17
17
NgModule ,
18
+ NgZone ,
18
19
OnDestroy ,
19
20
Output ,
20
21
} from '@angular/core' ;
@@ -153,7 +154,8 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy {
153
154
154
155
private _currentSubscription : Subscription | null = null ;
155
156
156
- constructor ( private _contentObserver : ContentObserver , private _elementRef : ElementRef ) { }
157
+ constructor ( private _contentObserver : ContentObserver , private _elementRef : ElementRef ,
158
+ private _ngZone : NgZone ) { }
157
159
158
160
ngAfterContentInit ( ) {
159
161
if ( ! this . _currentSubscription && ! this . disabled ) {
@@ -168,8 +170,15 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy {
168
170
private _subscribe ( ) {
169
171
this . _unsubscribe ( ) ;
170
172
const stream = this . _contentObserver . observe ( this . _elementRef . nativeElement ) ;
171
- this . _currentSubscription = ( this . debounce ? stream . pipe ( debounceTime ( this . debounce ) ) : stream )
172
- . subscribe ( mutations => this . event . next ( mutations ) ) ;
173
+
174
+ // TODO(mmalerba): We shouldn't be emitting on this @Output() outside the zone.
175
+ // Consider brining it back inside the zone next time we're making breaking changes.
176
+ // Bringing it back inside can cause things like infinite change detection loops and changed
177
+ // after checked errors if people's code isn't handling it properly.
178
+ this . _ngZone . runOutsideAngular ( ( ) => {
179
+ this . _currentSubscription =
180
+ ( this . debounce ? stream . pipe ( debounceTime ( this . debounce ) ) : stream ) . subscribe ( this . event ) ;
181
+ } ) ;
173
182
}
174
183
175
184
private _unsubscribe ( ) {
You can’t perform that action at this time.
0 commit comments