Skip to content

Commit e774692

Browse files
devversionjelbourn
authored andcommitted
fix(table): text-column throws if name input is set eagerly with ivy
Currently when someone uses the `CdkTextColumn` directive and sets the `name` input binding to a static value, Ivy will set the input value eagerly in the creation phase where the static query results are not available yet. This causes a runtime exception since the `this.columnDef` variable is still set to undefined when the `name` input setter executes.
1 parent 7f12235 commit e774692

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/cdk/table/text-column.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ export class CdkTextColumn<T> implements OnDestroy, OnInit {
7878
}
7979
set name(name: string) {
8080
this._name = name;
81-
this.columnDef.name = name;
81+
82+
// With Ivy, inputs can be initialized before static query results are
83+
// available. In that case, we defer the synchronization until "ngOnInit" fires.
84+
this._syncColumnDefName();
8285
}
8386
_name: string;
8487

@@ -127,6 +130,8 @@ export class CdkTextColumn<T> implements OnDestroy, OnInit {
127130
}
128131

129132
ngOnInit() {
133+
this._syncColumnDefName();
134+
130135
if (this.headerText === undefined) {
131136
this.headerText = this._createDefaultHeaderText();
132137
}
@@ -165,4 +170,11 @@ export class CdkTextColumn<T> implements OnDestroy, OnInit {
165170

166171
return this.name[0].toUpperCase() + this.name.slice(1);
167172
}
173+
174+
/** Synchronizes the column definition name with the text column name. */
175+
private _syncColumnDefName() {
176+
if (this.columnDef) {
177+
this.columnDef.name = this.name;
178+
}
179+
}
168180
}

0 commit comments

Comments
 (0)