我有两个单选按钮,我使用的是react 式表单,我在我的组件中添加了表单控件.我面临的问题是name属性必须与formControlName相同.当我将name属性设置为相同时,我只能 Select 一个单选按钮——不能取消 Select 并 Select 另一个.只允许我 Select 同一个.
this.genderControl = new FormControl("", Validators.required);
然后加入我的表格组
genderControl: this.genderControl,
我的HTML:
<div class="radio-inline">
<input id="gender" type="radio" name="genderControl" formControlName="genderControl" />
<label class="radio-label"> Male</label>
<input id="gender" type="radio" name="genderControl" formControlName="genderControl" />
<label class="radio-label">Female</label>
</div>
组队
this.personalInfo = new FormGroup({
searchControl: this.searchControl,
titleControl: this.titleControl,
firstNameControl: this.firstNameControl,
middleNameControl: this.middleNameControl,
lastNameControl: this.lastNameControl,
birthdayControl: this.birthdayControl,
genderControl: this.genderControl,
phoneControl: this.phoneControl,
taxCanadaControl: this.taxCanadaControl,
provinceControl: this.provinceControl,
countryControl: this.countryControl,
taxCountryControl: this.taxCountryControl,
creditControl: this.creditControl
});