@@ -307,7 +307,7 @@ export class CdkTable<T>
307307 private _document = inject ( DOCUMENT ) ;
308308
309309 /** Latest data provided by the data source. */
310- protected _data : readonly T [ ] ;
310+ protected _data : readonly T [ ] | undefined ;
311311
312312 /** Subject that emits when the component has been destroyed. */
313313 private readonly _onDestroy = new Subject < void > ( ) ;
@@ -621,17 +621,17 @@ export class CdkTable<T>
621621
622622 this . _isServer = ! this . _platform . isBrowser ;
623623 this . _isNativeHtmlTable = this . _elementRef . nativeElement . nodeName === 'TABLE' ;
624- }
625-
626- ngOnInit ( ) {
627- this . _setupStickyStyler ( ) ;
628624
629625 // Set up the trackBy function so that it uses the `RenderRow` as its identity by default. If
630626 // the user has provided a custom trackBy, return the result of that function as evaluated
631627 // with the values of the `RenderRow`'s data and index.
632628 this . _dataDiffer = this . _differs . find ( [ ] ) . create ( ( _i : number , dataRow : RenderRow < T > ) => {
633629 return this . trackBy ? this . trackBy ( dataRow . dataIndex , dataRow . data ) : dataRow ;
634630 } ) ;
631+ }
632+
633+ ngOnInit ( ) {
634+ this . _setupStickyStyler ( ) ;
635635
636636 this . _viewportRuler
637637 . change ( )
@@ -981,6 +981,10 @@ export class CdkTable<T>
981981 const prevCachedRenderRows = this . _cachedRenderRowsMap ;
982982 this . _cachedRenderRowsMap = new Map ( ) ;
983983
984+ if ( ! this . _data ) {
985+ return renderRows ;
986+ }
987+
984988 // For each data object, get the list of rows that should be rendered, represented by the
985989 // respective `RenderRow` object which is the pair of `data` and `CdkRowDef`.
986990 for ( let i = 0 ; i < this . _data . length ; i ++ ) {
0 commit comments