我试图使用formControl
中的disabled
属性.当我将其放入模板中时,它会起作用:
<md-input formControlName="id" placeholder="ID" [disabled]="true"></md-input>
但浏览器提醒我:
看起来您正在将disabled属性与被动表单一起使用
Example: form = new FormGroup({ first: new FormControl({value: 'Nancy', disabled: true}, Validators.required), last: new FormControl('Drew', Validators.required) });
所以我把它放进FormControl
,然后从模板中删除:
constructor(private itemsService: ItemsService) {
this._items = [];
this.myForm = new FormGroup({
id: new FormControl({value: '', disabled: true}, Validators.required),
title: new FormControl(),
description: new FormControl()
});
this.id = this.myForm.controls['id'];
this.title = this.myForm.controls['title'];
this.description = this.myForm.controls['description'];
this.id.patchValue(this._items.length);
}
但它不起作用(它并没有禁用input
).有什么问题吗?