@@ -21,7 +21,7 @@ import {
2121 ViewEncapsulation ,
2222} from '@angular/core' ;
2323import { animationFrameScheduler , fromEvent , Observable , Subject } from 'rxjs' ;
24- import { sampleTime , take , takeUntil } from 'rxjs/operators' ;
24+ import { sampleTime , takeUntil } from 'rxjs/operators' ;
2525import { CdkVirtualForOf } from './virtual-for-of' ;
2626import { VIRTUAL_SCROLL_STRATEGY , VirtualScrollStrategy } from './virtual-scroll-strategy' ;
2727
@@ -301,11 +301,7 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
301301 if ( ! this . _isChangeDetectionPending ) {
302302 this . _isChangeDetectionPending = true ;
303303 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 ( ) ;
309305 } ) ) ;
310306 }
311307 }
@@ -314,8 +310,10 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
314310 private _doChangeDetection ( ) {
315311 this . _isChangeDetectionPending = false ;
316312
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 ( ) ) ;
319317 // Apply the content transform. The transform can't be set via an Angular binding because
320318 // bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of
321319 // 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 {
330328 }
331329 }
332330
333- for ( const fn of this . _runAfterChangeDetection ) {
331+ const runAfterChangeDetection = this . _runAfterChangeDetection ;
332+ this . _runAfterChangeDetection = [ ] ;
333+ for ( const fn of runAfterChangeDetection ) {
334334 fn ( ) ;
335335 }
336- this . _runAfterChangeDetection = [ ] ;
337336 }
338337}
0 commit comments