角度单选按钮重置无法正常工作

库马拉

我正在为我的表单使用下面的单选按钮

<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';
}

我如何重新分配此单选按钮值

切拉潘w

您可以使用这样的初始值重置表单控件

 resetForm(reportlostkeyform: NgForm) {
      reportlostkeyform.reset({keys:'1'});
 }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章