我有一個表單控件,當頁面加載時我禁用。當用戶點擊一個按鈕時,表單應該被啓用進行編輯。但是,當我切換禁用控件的屬性時,什麼都不會發生。角度窗體控件禁用綁定不起作用
模板
<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
});
});
}
有趣的GitHub [主題](https://github.com/angular/angular/issues/11271#issuecomment-289806196)這裏 –
this.isEditing ...? – Thibs
[Angular 2:Disable input change not working]可能重複(https://stackoverflow.com/questions/39504565/angular-2-disable-input-change-not-working) – Alex