【发布时间】:2019-09-18 19:03:47
【问题描述】:
我创建了一组单选按钮。我想设置一个默认单选按钮“已选中”,并且每当动态单击其他单选按钮时,我如何捕获哪个单选按钮。所以,我可以在我的打字稿的条件语句中相应地使用它。“CHECKED”标签将不起作用
<form [formGroup]="Form">
<div class="bx--row">
<fieldset class="bx--fieldset">
<legend class="bx--label">HEYHELLOWORLD</legend>
<div class="bx--form-item">
<div class="bx--radio-button-group ">
<input id="radio-button-1" class="bx--radio-button" type="radio" formControlName="selectedOption"
value="0" checked>
<label for="radio-button-1" class="bx--radio-button__label">
<span class="bx--radio-button__appearance"></span>
HEY<br>
</label>
<input id="radio-button-2" class="bx--radio-button" type="radio" formControlName="selectedOption"
value="1" tabindex="0">
<label for="radio-button-2" class="bx--radio-button__label">
<span class="bx--radio-button__appearance"></span>
HELLO<br>
</label>
<input id="radio-button-3" class="bx--radio-button" type="radio" formControlName="selectedOption"
value="2" tabindex="0">
<label for="radio-button-3" class="bx--radio-button__label">
<span class="bx--radio-button__appearance"></span>
WORLD
</label>
</div>
</div>
</fieldset>
</div>
</form>
上面是我的反应形式的 HTML 部分 TS:
heyForm() {
this.Form = this.formBuilder.group({
selectedOption: ["", Validators.required],
});
}
如何获取 TS 文件中选择的值,以便我可以使用在条件语句中单击了哪个单选按钮?
【问题讨论】:
标签: angular radio-button radio-group reactive-forms