Javascript Angular2表单重置,在表单重置或提交后取消选中收音机
如何在ng2中重置表单,我已经准备好使用方法form.reset(),但重置后我仍然选中表单上的复选框。问题是,如何取消选中表单中的复选框Javascript Angular2表单重置,在表单重置或提交后取消选中收音机,javascript,angular,typescript,Javascript,Angular,Typescript,如何在ng2中重置表单,我已经准备好使用方法form.reset(),但重置后我仍然选中表单上的复选框。问题是,如何取消选中表单中的复选框 <form #f="ngForm" [formGroup]="taskCreate" (submit)="onSubmit(taskCreate)"> <fieldset class="form-group"> <label for="goal">Cel: </label&
<form #f="ngForm" [formGroup]="taskCreate" (submit)="onSubmit(taskCreate)">
<fieldset class="form-group">
<label for="goal">Cel: </label>
<select name="goal" class="form-control" formControlName="goal" ngControl="goal">
<option *ngFor="let goal of goals" [value]="goal.key" [selected]="key === 'first'">{{ goal.value }}</option>
</select>
<div class="alert alert-danger" *ngIf="this.formValid.goalErr">You must select a goal.</div>
</fieldset>
<fieldset class="form-group">
<label for="p">Priorytet:</label>
<div name="p">
<input class="priority" style="display: table-cell; vertical-align: text-bottom;" type="radio" value="PML" name="priority" formControlName="priority">
<img style="margin-right: 5px;" [src]="this.minustwo" alt="minustwo" />
<input class="priority" style="display: table-cell; vertical-align: text-bottom;" type="radio" value="PL" name="priority" formControlName="priority">
<img style="margin-right: 5px;" [src]="this.minusone" alt="minusone" />
<input class="priority" style="display: table-cell; vertical-align: text-bottom;" type="radio" value="PN" name="priority" formControlName="priority">
<img style="margin-right: 5px;" [src]="this.zero" alt="zero" />
<input class="priority" style="display: table-cell; vertical-align: text-bottom;" type="radio" value="PH" name="priority" formControlName="priority">
<img style="margin-right: 5px;" [src]="this.plusone" alt="plusone" />
<input class="priority" style="display: table-cell; vertical-align: text-bottom;" type="radio" value="PMH" name="priority" formControlName="priority">
<img style="margin-right: 5px;" [src]="this.plustwo" alt="plustwo" />
</div>
<div class="alert alert-danger" *ngIf="this.formValid.priorityErr">You must select a priority.</div>
</fieldset>
<fieldset class="form-group">
<label for="note">Uwagi do zadania:</label>
<textarea maxlength="2000" class="form-control" name="note" rows="8" cols="40" formControlName="note"></textarea>
<div class="alert alert-danger" *ngIf="this.formValid.noteErr">You must draw a note.</div>
</fieldset>
[...]
问候!
博斯珀=RC.6 在RC.6中,应该支持更新表单模型。创建新表单组并分配给
myForm
[formGroup]="myForm"
也将被支持()
=RC.5
form.reset();
在新表单模块(>=RC.5)中,NgForm
有一个reset()
方法,还支持表单reset
事件。
您可能需要重置每个表单控件 reset()可以接受由所有FormControl组成的对象。由于您尚未发布如何使用form.reset,请尝试以下方法 例如,尝试以下方法:
this.taskCreate.reset({
goal: '',
prodCodeList: '',
note: '',
priority: '',
attachmentList: ''
})
这将重置您拥有的每个formcontrol,这意味着它们将保持原样
文档。在我的例子中,form.reset会重置所有表单控件,但不会取消选中onlu单选按钮。该值为null且未点击,
this.taskCreate.reset({
goal: '',
prodCodeList: '',
note: '',
priority: '',
attachmentList: ''
})