Skip to content

Commit 7a1118a

Browse files
committed
fix(cdk/observers): Run content changed callback in NgZone
1 parent f10a158 commit 7a1118a

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

src/cdk/observers/observe-content.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
Injectable,
1616
Input,
1717
NgModule,
18-
NgZone,
1918
OnDestroy,
2019
Output,
2120
booleanAttribute,
@@ -202,7 +201,6 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy {
202201
constructor(
203202
private _contentObserver: ContentObserver,
204203
private _elementRef: ElementRef<HTMLElement>,
205-
private _ngZone: NgZone,
206204
) {}
207205

208206
ngAfterContentInit() {
@@ -219,15 +217,9 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy {
219217
this._unsubscribe();
220218
const stream = this._contentObserver.observe(this._elementRef);
221219

222-
// TODO(mmalerba): We shouldn't be emitting on this @Output() outside the zone.
223-
// Consider brining it back inside the zone next time we're making breaking changes.
224-
// Bringing it back inside can cause things like infinite change detection loops and changed
225-
// after checked errors if people's code isn't handling it properly.
226-
this._ngZone.runOutsideAngular(() => {
227-
this._currentSubscription = (
228-
this.debounce ? stream.pipe(debounceTime(this.debounce)) : stream
229-
).subscribe(this.event);
230-
});
220+
this._currentSubscription = (
221+
this.debounce ? stream.pipe(debounceTime(this.debounce)) : stream
222+
).subscribe(this.event);
231223
}
232224

233225
private _unsubscribe() {

tools/public_api_guard/cdk/observers.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import { AfterContentInit } from '@angular/core';
88
import { ElementRef } from '@angular/core';
99
import { EventEmitter } from '@angular/core';
1010
import * as i0 from '@angular/core';
11-
import { NgZone } from '@angular/core';
1211
import { NumberInput } from '@angular/cdk/coercion';
1312
import { Observable } from 'rxjs';
1413
import { OnDestroy } from '@angular/core';
1514

1615
// @public
1716
export class CdkObserveContent implements AfterContentInit, OnDestroy {
18-
constructor(_contentObserver: ContentObserver, _elementRef: ElementRef<HTMLElement>, _ngZone: NgZone);
17+
constructor(_contentObserver: ContentObserver, _elementRef: ElementRef<HTMLElement>);
1918
get debounce(): number;
2019
set debounce(value: NumberInput);
2120
get disabled(): boolean;

0 commit comments

Comments
 (0)