我有一个在页面加载时禁用的表单控件。当用户单击按钮时,表单应该可以进行编辑。但是,当我切换禁用控件的属性时,什么也没有发生。
模板
<form [formGroup]='accountForm'>
<md-input-container>
<input mdInput formControlName='name' />
</md-input-container>
<button (click)='isEditing = !isEditing'>Edit</button>
</form>
零件
export class AccountComponent {
private accountForm: FormGroup;
private isEditing = false;
private name: FormControl = new FormControl({ value: '', disabled: !isEditing;
constructor(
formBuilder: FormBuilder
) {
this.accountForm = formBuilder.group({
'name': this.name
});
});
}