我有一个组件,该组件由另一个包含某些下拉菜单的组件组成。 我的问题是出现错误:
ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'value: null'. Current value: 'value: 2019'.
这是我尝试过的代码。
我不确定该如何解决。
<app-task-parameter
[parameterType]="param"
[(value)]="this.parameters[param]">
</app-task-parameter>
private _parameterType: string;
@Input() set parameterType(parameterType) {
this._parameterType = parameterType;
this.processParameterType(parameterType);
}
@Output() valueChange = new EventEmitter();
private _value: any = null;
private defaultValue: any = null;
@Input() set value(value: any) {
console.log("initial value", value);
if(value === null) {
this._value = this.defaultValue;
} else {
if(this.paramDefinitions[this.parameterType]["type"] === "integer") {
value = parseInt(value);
}
this._value = value;
}
this.emitValue();
}
get value() {
return this._value;
}
emitValue() {
console.log('value set: ', this.value);
this.valueChange.emit(this.value);
//this.valueChange.emit(this.value);
}