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.
This commit is contained in:
Paul Gschwendtner
2019-05-14 15:40:45 +02:00
committed by Jeremy Elbourn
parent 7f1223504f
commit e774692ba0
+13 -1
View File
@@ -78,7 +78,10 @@ export class CdkTextColumn<T> implements OnDestroy, OnInit {
}
set name(name: string) {
this._name = name;
this.columnDef.name = name;
// With Ivy, inputs can be initialized before static query results are
// available. In that case, we defer the synchronization until "ngOnInit" fires.
this._syncColumnDefName();
}
_name: string;
@@ -127,6 +130,8 @@ export class CdkTextColumn<T> implements OnDestroy, OnInit {
}
ngOnInit() {
this._syncColumnDefName();
if (this.headerText === undefined) {
this.headerText = this._createDefaultHeaderText();
}
@@ -165,4 +170,11 @@ export class CdkTextColumn<T> implements OnDestroy, OnInit {
return this.name[0].toUpperCase() + this.name.slice(1);
}
/** Synchronizes the column definition name with the text column name. */
private _syncColumnDefName() {
if (this.columnDef) {
this.columnDef.name = this.name;
}
}
}