@@ -107,16 +107,14 @@ export class CdkVirtualScrollViewport implements DoCheck, OnInit, OnDestroy {
107
107
@Inject ( VIRTUAL_SCROLL_STRATEGY ) private _scrollStrategy : VirtualScrollStrategy ) { }
108
108
109
109
ngOnInit ( ) {
110
- const viewportEl = this . elementRef . nativeElement ;
111
110
// It's still too early to measure the viewport at this point. Deferring with a promise allows
112
111
// the Viewport to be rendered with the correct size before we measure.
113
112
Promise . resolve ( ) . then ( ( ) => {
114
- this . _viewportSize = this . orientation === 'horizontal' ?
115
- viewportEl . clientWidth : viewportEl . clientHeight ;
113
+ this . _measureViewportSize ( ) ;
116
114
this . _scrollStrategy . attach ( this ) ;
117
115
118
116
this . _ngZone . runOutsideAngular ( ( ) => {
119
- fromEvent ( viewportEl , 'scroll' )
117
+ fromEvent ( this . elementRef . nativeElement , 'scroll' )
120
118
// Sample the scroll stream at every animation frame. This way if there are multiple
121
119
// scroll events in the same frame we only need to recheck our layout once.
122
120
. pipe ( sampleTime ( 0 , animationFrameScheduler ) , takeUntil ( this . _destroyed ) )
@@ -307,4 +305,18 @@ export class CdkVirtualScrollViewport implements DoCheck, OnInit, OnDestroy {
307
305
}
308
306
return this . _forOf . measureRangeSize ( range , this . orientation ) ;
309
307
}
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
+ }
310
322
}
0 commit comments