【发布时间】:2017-01-12 15:33:18
【问题描述】:
这就是我在 rc6 中设置表单的方式:
this.myForm = fb.group({
lambda: new FormControl({value: .94, disabled: true}, Validators.required),
//lambda: ['',[Validators.required]],
radio11: ['es',[Validators.required]],
startdate: ['',[Validators.required]],
enddate: ['',[Validators.required]]
})
因此,在表单更改时,我订阅事件并根据条件将禁用的字段从 true 更改为 false:
this.myForm.valueChanges.do(formValue=>{
console.log(formValue);
console.log(formValue.radio11);
if (formValue.radio11=='es'){
console.log(this.myForm.controls.lambda.disabled);
}
}).subscribe();
例如,如果我将以下设置为 false,则会收到以下错误
this.myForm.controls.lambda.disabled=false
core.umd.js:5995 EXCEPTION: Uncaught (in promise): Error: Error in app/model_parameters_general/model_parameters_general.component.html:19:27 caused by: Cannot set property disabled of #<AbstractControl> which has only a getter
【问题讨论】: