我已经构建了一个 Angular Reactive Form。在它上面我有 2 个单选按钮,默认选择一个(但是在我的示例中它没有在 UI 上显示为选中)。
我有一个 ngIf div,如果单选按钮已更改或触摸 || 则应显示它脏,例如
<div formGroupName="radioButtons" class="form-group col-6 pl-0 pt-3">
<div class="form-check-inline">
<label for="yes" class="col-12 customradio"
><span>yes</span>
<input value="yes" id="yes" type="radio" name="radiot" formControlName="radiot"/>
</label>
<label for="no" class="customradio"
><span>no</span>
<input value="no" id="no" type="radio" name="radiot" formControlName="radiot" />
</label>
</div>
<div class="form-check__related" *ngIf="radioButtons.radiot.touched">
DISPLAY ME
</div>
但是,我无法让它工作并得到
Error: Cannot read property 'radiot' of undefined
最佳答案
直接替换
*ngIf="radioButtons.radiot.touched"
与
*ngIf="form.controls.radioButtons.touched"
你的问题将会得到解决
关于javascript - 检查单选按钮是否脏/以 react 形式被触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58819871/