我有一个响应式(Reactive)表单,其中有一个单选按钮组可在一个表单变量上工作,并且在我重置表单之前一直有效。当我重置表单时,两个 radio 都被取消选择。
<mat-radio-group aria-label="Select an option" formControlName="IsUnderLc">
<mat-radio-button value="true" [checked]="workTransactionForm.controls['IsUnderLc'].value == true">
Under LC
</mat-radio-button>
<mat-radio-button value="false[checked]="workTransactionForm.controls['IsUnderLc'].value == false">
Collection
</mat-radio-button>
</mat-radio-group>
我想保留一个选择,我什至尝试修补值并在 FormGroup 中提供默认值,但没有任何效果。
this.workTransactionForm.reset();
this.workTransactionForm.controls.IsUnderLc.setValue(true);
在重置表单后,是否有任何可能的方法来设置表单控件的值?
最佳答案
我可以在更改 html 代码后解决问题 来自
<mat-radio-button value="false" [checked]="workTransactionForm.controls['IsUnderLc'].value == false">
Collection
</mat-radio-button>
到
<mat-radio-button value="false>
Collection
</mat-radio-button>
然后在 .ts 文件中再次绑定(bind)它
this.workTransactionForm.controls.IsFresh.patchValue(false);
this.workTransactionForm.controls.IsUnderLc.patchValue(false);
关于angular - 单选按钮清除表单重置 Angular 6 上的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56145996/