我正在使用ReactiveFormsModuleAngular2 创建一个包含表单的组件。这是我的代码:
foo.component.ts
constructor(fb: FormBuilder) {
this.myForm = fb.group({
'name': ['', Validators.required],
'surname': ['', Validators.required],
'gender': []
});
}
foo.component.html
<div class="two fields">
<div class="four wide field">
<label>Name*</label>
<input type="text" [formControl]="myForm.controls.name"/>
</div>
<div class="four wide field">
<label>Surname*</label>
<input type="text" [formControl]="myForm.controls.surname"/>
</div>
</div>
<div class="inline fields">
<label for="gender">Gender</label>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="gender" checked="" tabindex="0" class="hidden" [formControl]="myForm.controls.gender">
<label>Male</label>
</div>
</div>
<div class="field">
<div class="ui radio checkbox">
<input type="radio" name="gender" tabindex="0" class="hidden" [formControl]="myForm.controls.gender">
<label>Female</label>
</div>
</div>
</div>
我在上面发布的代码不起作用:如果我单击两个单选按钮之一,它总是选择第二个并且我无法更改它。
FormControl使用radio(或)的正确方法是什么checkbox?