@@ -18,7 +18,7 @@ import {
18
18
ViewChild ,
19
19
ViewEncapsulation
20
20
} from '@angular/core' ;
21
- import { CdkColumnDef } from './cell' ;
21
+ import { CdkCellDef , CdkColumnDef , CdkHeaderCellDef } from './cell' ;
22
22
import { CdkTable } from './table' ;
23
23
import { getTableTextColumnMissingParentTableError } from './table-errors' ;
24
24
@@ -99,8 +99,27 @@ export class CdkTextColumn<T> implements OnDestroy, OnInit {
99
99
/** Alignment of the cell values. */
100
100
@Input ( ) justify : 'start' | 'end' = 'start' ;
101
101
102
+ /** @docs -private */
102
103
@ViewChild ( CdkColumnDef , { static : true } ) columnDef : CdkColumnDef ;
103
104
105
+ /**
106
+ * The column cell is provided to the column during `ngOnInit` with a static query.
107
+ * Normally, this will be retrieved by the column using `ContentChild`, but that assumes the
108
+ * column definition was provided in the same view as the table, which is not the case with this
109
+ * component.
110
+ * @docs -private
111
+ */
112
+ @ViewChild ( CdkCellDef , { static : true } ) cell : CdkCellDef ;
113
+
114
+ /**
115
+ * The column headerCell is provided to the column during `ngOnInit` with a static query.
116
+ * Normally, this will be retrieved by the column using `ContentChild`, but that assumes the
117
+ * column definition was provided in the same view as the table, which is not the case with this
118
+ * component.
119
+ * @docs -private
120
+ */
121
+ @ViewChild ( CdkHeaderCellDef , { static : true } ) headerCell : CdkHeaderCellDef ;
122
+
104
123
constructor (
105
124
@Optional ( ) private table : CdkTable < T > ,
106
125
@Optional ( ) @Inject ( TEXT_COLUMN_OPTIONS ) private options : TextColumnOptions < T > ) {
@@ -118,6 +137,11 @@ export class CdkTextColumn<T> implements OnDestroy, OnInit {
118
137
}
119
138
120
139
if ( this . table ) {
140
+ // Provide the cell and headerCell directly to the table with the static `ViewChild` query,
141
+ // since the columnDef will not pick up its content by the time the table finishes checking
142
+ // its content and initializing the rows.
143
+ this . columnDef . cell = this . cell ;
144
+ this . columnDef . headerCell = this . headerCell ;
121
145
this . table . addColumnDef ( this . columnDef ) ;
122
146
} else {
123
147
throw getTableTextColumnMissingParentTableError ( ) ;
0 commit comments