【发布时间】:2023-03-05 22:18:01
【问题描述】:
我有两个材料单选按钮,其中一个在我的 Angular 反应表单中设置为默认值。表单提交后(留在同一页面上),我想对所有表单控件进行重置,并将默认选中的单选按钮返回到选中模式。
所以我在我的 TS 中创建了一个 radioBtnDefault 道具并将其设置为 true,在表单重置后我尝试将其设置为 false 然后返回到 true 但我似乎表单重置功能没有t 完成,直到该值返回 true,因为当我使用 setTimeOut 并稍有延迟时,它可以正常工作。
任何关于如何在没有 setTimeOut 函数的情况下使用它的建议将不胜感激。
HTML
<mat-radio-button class="inner-container__form__inputs__participants__buttons__btn" [checked]="radioBtnDefault" value="1"
(click)="onClickedOneParticipant()">No
</mat-radio-button>
TS
this.editMode = false;
this.formSubmitted = false;
this.colorSelectionOpen = false;
this.radioBtnDefault = false;
this.appointmentsCreationForm.reset();
this.appointmentsCreationForm.get('participants').setValue('1');
this.selectedBackgroundColor = '#EB5757';
this.selectedTextColor = '#FFF';
setTimeout(() => {
this.radioBtnDefault = true;
}, 100);
【问题讨论】:
标签: angular