Skip to content

Commit 94a8531

Browse files
committed
revert static query in cell; directly provide cells to column
1 parent c10039c commit 94a8531

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/cdk/table/cell.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ export class CdkColumnDef extends _CdkColumnDefBase implements CanStick {
9393
_stickyEnd: boolean = false;
9494

9595
/** @docs-private */
96-
@ContentChild(CdkCellDef, {static: true}) cell: CdkCellDef;
96+
@ContentChild(CdkCellDef, {static: false}) cell: CdkCellDef;
9797

9898
/** @docs-private */
99-
@ContentChild(CdkHeaderCellDef, {static: true}) headerCell: CdkHeaderCellDef;
99+
@ContentChild(CdkHeaderCellDef, {static: false}) headerCell: CdkHeaderCellDef;
100100

101101
/** @docs-private */
102-
@ContentChild(CdkFooterCellDef, {static: true}) footerCell: CdkFooterCellDef;
102+
@ContentChild(CdkFooterCellDef, {static: false}) footerCell: CdkFooterCellDef;
103103

104104
/**
105105
* Transformed version of the column name that can be used as part of a CSS classname. Excludes

src/cdk/table/text-column.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
ViewChild,
1919
ViewEncapsulation
2020
} from '@angular/core';
21-
import {CdkColumnDef} from './cell';
21+
import {CdkCellDef, CdkColumnDef, CdkHeaderCellDef} from './cell';
2222
import {CdkTable} from './table';
2323
import {getTableTextColumnMissingParentTableError} from './table-errors';
2424

@@ -99,8 +99,27 @@ export class CdkTextColumn<T> implements OnDestroy, OnInit {
9999
/** Alignment of the cell values. */
100100
@Input() justify: 'start'|'end' = 'start';
101101

102+
/** @docs-private */
102103
@ViewChild(CdkColumnDef, {static: true}) columnDef: CdkColumnDef;
103104

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+
104123
constructor(
105124
@Optional() private table: CdkTable<T>,
106125
@Optional() @Inject(TEXT_COLUMN_OPTIONS) private options: TextColumnOptions<T>) {
@@ -118,6 +137,11 @@ export class CdkTextColumn<T> implements OnDestroy, OnInit {
118137
}
119138

120139
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;
121145
this.table.addColumnDef(this.columnDef);
122146
} else {
123147
throw getTableTextColumnMissingParentTableError();

0 commit comments

Comments
 (0)