当用户从下拉列表中选择roeType作为'Daily ROE'时,我想要做的就是在我的表单中禁用'toDate'输入字段。如何实现这个是angular2的模型驱动形式。
createAddROEForm() {
this.addRoeForm = this.formBuilder.group({
roeTypeId: [],
roeType: [],
roeSource: [],
supplierName: [],
fromDate: [],
toDate: [{value:'', disabled:(this.addRoeForm.value.roeType='Daily ROE')}],
status: [],
reason: [],
companyMarket: [],
productCategory: ['',Validators.required],
productSubType: ['',Validators.required],
productName: ['',Validators.required],
})
答案 0 :(得分:0)
toDate: [{value:'', disabled: this.addRoeForm.value.roeType==='Daily ROE'}],
答案 1 :(得分:0)
<form [formGroup]='addRoeForm'>
<select (change)="dummyMethod()">
<option></option>
<select>
</form>
从HTML调用此方法中的方法dummyMethod()
dummyMethod(){
if(this.addRoeForm.get('roeType').value == 'Daily ROE'){
this.addRowForm.controls.toDate.disable();
}}
并在component.ts文件的类中定义方法。