@@ -107,16 +107,14 @@ export class CdkVirtualScrollViewport implements DoCheck, OnInit, OnDestroy {
107107 @Inject ( VIRTUAL_SCROLL_STRATEGY ) private _scrollStrategy : VirtualScrollStrategy ) { }
108108
109109 ngOnInit ( ) {
110- const viewportEl = this . elementRef . nativeElement ;
111110 // It's still too early to measure the viewport at this point. Deferring with a promise allows
112111 // the Viewport to be rendered with the correct size before we measure.
113112 Promise . resolve ( ) . then ( ( ) => {
114- this . _viewportSize = this . orientation === 'horizontal' ?
115- viewportEl . clientWidth : viewportEl . clientHeight ;
113+ this . _measureViewportSize ( ) ;
116114 this . _scrollStrategy . attach ( this ) ;
117115
118116 this . _ngZone . runOutsideAngular ( ( ) => {
119- fromEvent ( viewportEl , 'scroll' )
117+ fromEvent ( this . elementRef . nativeElement , 'scroll' )
120118 // Sample the scroll stream at every animation frame. This way if there are multiple
121119 // scroll events in the same frame we only need to recheck our layout once.
122120 . pipe ( sampleTime ( 0 , animationFrameScheduler ) , takeUntil ( this . _destroyed ) )
@@ -307,4 +305,18 @@ export class CdkVirtualScrollViewport implements DoCheck, OnInit, OnDestroy {
307305 }
308306 return this . _forOf . measureRangeSize ( range , this . orientation ) ;
309307 }
308+
309+ /** Update the viewport dimensions and re-render. */
310+ checkViewportSize ( ) {
311+ // TODO: Cleanup later when add logic for handling content resize
312+ this . _measureViewportSize ( ) ;
313+ this . _scrollStrategy . onDataLengthChanged ( ) ;
314+ }
315+
316+ /** Measure the viewport size. */
317+ private _measureViewportSize ( ) {
318+ const viewportEl = this . elementRef . nativeElement ;
319+ this . _viewportSize = this . orientation === 'horizontal' ?
320+ viewportEl . clientWidth : viewportEl . clientHeight ;
321+ }
310322}
0 commit comments