angular - 角度单选按钮重置无法正常工作
问题描述
我正在为我的表单使用下面的单选按钮
<input type="radio" class="form-check-input" value="1" [checked]="true" name="keys" [(ngModel)]="lostkey.key">One
<input type="radio" name="keys" value="2" [(ngModel)]="lostkey.key" class="form-check-input">Both
我使用以下代码将“一个”单选按钮设置为默认值
ngOnInit() {
this.lostkey.key = '1';
}
这是我的重置按钮。这运作良好。所有表格重置。但问题是,默认单选按钮也未选中。因此我在表格重置后重新分配它。但它没有用。
重置按钮(这是正常工作)
<button type="button" class="btn btn-action btn-flat float-right"
(click)="resetForm(reportlostkeyform)">
<i class="fas fa-redo"></i> <span> Reset</span>
</button>
这是重置功能
resetForm(reportlostkeyform: NgForm) {
reportlostkeyform.reset();
this.lostkey.key = '1';
}
我如何重新分配此单选按钮值
解决方案
尝试重置 setTimeout 中的值;
resetForm(reportlostkeyform: NgForm) {
reportlostkeyform.reset();
setTimeout(() => {
this.lostkey.key = '1';
})
}
推荐阅读
- php - 如何在单击行特定按钮时将从数据库获取的记录值传递到其他 PHP 页面
- python - 熊猫:根据其他列和值本身更改单元格值
- forms - 如果值然后将字段设置为日期,则 MS Access 组合框?
- xcode - Xcode 不会让我提交整个项目(只会让我提交单个文件)
- php - 用于捕获 URL 中的 ID 号的正则表达式
- r - 如何使用 R Shiny downloadHandler 下载 ggplotly 图?
- svelte - Svelte - 在点击处理程序中更改绑定值似乎不会更新它
- pandas - 如何对整列而不是每列的熊猫数据框进行一次热编码?
- oracle - 如何配置 Camunda 7.10(Wildfly 完整发行版)以使用 Oracle 数据库?
- robotframework - 如何剥离 URL 的一部分并分配给变量