Html 切换radiobatton时如何启用和禁用输入文件?
我有一个表单,我需要根据单选按钮的位置在同一表单中无法和禁用控件Html 切换radiobatton时如何启用和禁用输入文件?,html,angular,Html,Angular,我有一个表单,我需要根据单选按钮的位置在同一表单中无法和禁用控件 <form [formGroup]="service.form" #signUpForm="ngForm" class="normal-form"> -------------------------------------------------------------- <mat-radio-group formControlName="role"> <mat-ra
<form [formGroup]="service.form" #signUpForm="ngForm" class="normal-form">
--------------------------------------------------------------
<mat-radio-group formControlName="role">
<mat-radio-button value="1">Patient</mat-radio-button>
<mat-radio-button value="2">Doctor</mat-radio-button>
</mat-radio-group>
--------------------------------------------------------------
<input type="file" #Image accept="image/*" [disabled]="service.form.role==1">
</form>
--------------------------------------------------------------
病人
医生
--------------------------------------------------------------
如何执行此操作?只需提供对role元素的引用,并使用reference来禁用和启用其他控件
<form [formGroup]="service.form" #signUpForm="ngForm" class="normal-form">
--------------------------------------------------------------
<mat-radio-group #role formControlName="role">
<mat-radio-button value="1">Patient</mat-radio-button>
<mat-radio-button value="2">Doctor</mat-radio-button>
</mat-radio-group>
--------------------------------------------------------------
<input type="file" #Image accept="image/*" [disabled]="role.value==1">
</form>
--------------------------------------------------------------
病人
医生
--------------------------------------------------------------
只需引用role元素,并使用reference来禁用和启用其他控件
<form [formGroup]="service.form" #signUpForm="ngForm" class="normal-form">
--------------------------------------------------------------
<mat-radio-group #role formControlName="role">
<mat-radio-button value="1">Patient</mat-radio-button>
<mat-radio-button value="2">Doctor</mat-radio-button>
</mat-radio-group>
--------------------------------------------------------------
<input type="file" #Image accept="image/*" [disabled]="role.value==1">
</form>
--------------------------------------------------------------
病人
医生
--------------------------------------------------------------
您将无法在服务表单
上获得角色
<代码>服务。表单将有一个值
属性,您将从中获得此角色
属性
只需使用service.form.value.role
而不是service.form.role
<form [formGroup]="form" #signUpForm="ngForm" class="normal-form">
<mat-radio-group formControlName="role">
<mat-radio-button value="1">Patient</mat-radio-button>
<mat-radio-button value="2">Doctor</mat-radio-button>
</mat-radio-group>
<br>
<input type="file" #Image accept="image/*" [disabled]="form.value.role==1">
</form>
病人
医生
这里有一个供您参考的文件。您将无法在
service.form
上获得role
<代码>服务。表单将有一个值
属性,您将从中获得此角色
属性
只需使用service.form.value.role
而不是service.form.role
<form [formGroup]="form" #signUpForm="ngForm" class="normal-form">
<mat-radio-group formControlName="role">
<mat-radio-button value="1">Patient</mat-radio-button>
<mat-radio-button value="2">Doctor</mat-radio-button>
</mat-radio-group>
<br>
<input type="file" #Image accept="image/*" [disabled]="form.value.role==1">
</form>
病人
医生
这是一个供参考的示例。我将[disabled]=“service.form.role==1”更改为[disabled]=“role.value==1”,并添加了#role,但这对我没有帮助。С还需要其他东西吗?因为值在字符串中,所以使用
[disabled]=“role.value=='1'”
角度材质可能以不同的方式工作。尝试@SiddAjmera给出的解决方案。看起来很有希望。我将[disabled]=“service.form.role==1”更改为[disabled]=“role.value==1”,并添加了#role,但这对我没有帮助。С还需要其他东西吗?因为值在字符串中,所以使用[disabled]=“role.value=='1'”
角度材质可能以不同的方式工作。尝试@SiddAjmera给出的解决方案。看起来很有希望。