@@ -21,7 +21,7 @@ import {
21
21
ViewEncapsulation ,
22
22
} from '@angular/core' ;
23
23
import { animationFrameScheduler , fromEvent , Observable , Subject } from 'rxjs' ;
24
- import { sampleTime , take , takeUntil } from 'rxjs/operators' ;
24
+ import { sampleTime , takeUntil } from 'rxjs/operators' ;
25
25
import { CdkVirtualForOf } from './virtual-for-of' ;
26
26
import { VIRTUAL_SCROLL_STRATEGY , VirtualScrollStrategy } from './virtual-scroll-strategy' ;
27
27
@@ -301,11 +301,7 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
301
301
if ( ! this . _isChangeDetectionPending ) {
302
302
this . _isChangeDetectionPending = true ;
303
303
this . _ngZone . runOutsideAngular ( ( ) => Promise . resolve ( ) . then ( ( ) => {
304
- if ( this . _ngZone . isStable ) {
305
- this . _doChangeDetection ( ) ;
306
- } else {
307
- this . _ngZone . onStable . pipe ( take ( 1 ) ) . subscribe ( ( ) => this . _doChangeDetection ( ) ) ;
308
- }
304
+ this . _doChangeDetection ( ) ;
309
305
} ) ) ;
310
306
}
311
307
}
@@ -314,8 +310,10 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
314
310
private _doChangeDetection ( ) {
315
311
this . _isChangeDetectionPending = false ;
316
312
317
- // Apply changes to Angular bindings.
318
- this . _ngZone . run ( ( ) => this . _changeDetectorRef . detectChanges ( ) ) ;
313
+ // Apply changes to Angular bindings. Note: We must call `markForCheck` to run change detection
314
+ // from the root, since the repeated items are content projected in. Calling `detectChanges`
315
+ // instead does not properly check the projected content.
316
+ this . _ngZone . run ( ( ) => this . _changeDetectorRef . markForCheck ( ) ) ;
319
317
// Apply the content transform. The transform can't be set via an Angular binding because
320
318
// bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of
321
319
// string literals, a variable that can only be 'X' or 'Y', and user input that is run through
@@ -330,9 +328,10 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
330
328
}
331
329
}
332
330
333
- for ( const fn of this . _runAfterChangeDetection ) {
331
+ const runAfterChangeDetection = this . _runAfterChangeDetection ;
332
+ this . _runAfterChangeDetection = [ ] ;
333
+ for ( const fn of runAfterChangeDetection ) {
334
334
fn ( ) ;
335
335
}
336
- this . _runAfterChangeDetection = [ ] ;
337
336
}
338
337
}
0 commit comments