Angular 角复位反应式
我试图在发送表单后重置表单,但只有该值设置为null component.html 问题是输入字段被标记为脏,如下所示: 您可以使用ngForm来执行此操作 在Html文件中 在HTML和TS文件中相应地替换名称。您可以使用ngForm来执行此操作 在Html文件中 相应地替换HTML和TS文件中的名称。尝试使用按钮类型=重置选项 尝试使用按钮类型=重置选项 您可以使用如下的formGroup重置方法click=noteForm.reset,此方法将标记所有子体都标记为原始且未触及,并且所有子体的值都为null 范例 需要说明 Add您可以像这样使用formGroup重置方法click=noteForm.reset,此方法将标记所有子体都被标记为原始和未触及,并且所有子体的值都为null 范例 需要说明Angular 角复位反应式,angular,angular-reactive-forms,reset,reactive-forms,Angular,Angular Reactive Forms,Reset,Reactive Forms,我试图在发送表单后重置表单,但只有该值设置为null component.html 问题是输入字段被标记为脏,如下所示: 您可以使用ngForm来执行此操作 在Html文件中 在HTML和TS文件中相应地替换名称。您可以使用ngForm来执行此操作 在Html文件中 相应地替换HTML和TS文件中的名称。尝试使用按钮类型=重置选项 尝试使用按钮类型=重置选项 您可以使用如下的formGroup重置方法click=noteForm.reset,此方法将标记所有子体都标记为原始且未触及,并且所有子体
Add似乎是问题的重复:@Ivilin Stouanov,请阅读有关使用resetForm或type=reset.reset的内容。reset将通过标记将FormGroup重置所有子体标记为原始和未触及,并将所有子体的值重置为null。似乎是问题的重复:@Ivilin Stouanov,请阅读有关使用resetForm或type=reset.reset的内容。reset将通过标记来重置FormGroup所有子体都标记为原始且未触及,并且所有子体的值都为null。这将重置起始,但他在单击“保存并从组件体运行插入注释方法”后尝试重置。这将重置起始,但他在单击“保存并从组件体运行插入注释方法”后尝试重置
<div *ngIf="!loading" fxLayout="row" class="note-textarea">
<form fxFlex fxLayout="column" fxLayoutGap="10px" [formGroup]="noteForm">
<mat-form-field fxFlex>
<textarea matInput #note rows="1" maxlength="100" placeholder="Note" formControlName="description"></textarea>
<mat-hint align="end">{{note.value?.length || 0}}/100</mat-hint>
<mat-error *ngIf="noteForm.get('description').errors && noteForm.get('description').touched">description is required</mat-error>
</mat-form-field>
<div fxFlex>
<button mat-stroked-button class="save-btn" (click)="insertNote()">Save</button>
</div>
</form>
</div>
noteForm: FormGroup = this.formBuilder.group({
description: new FormControl(null, Validators.required)
})
insertNote() {
// bunch of code
this.noteForm.reset();
}
}
<form fxFlex fxLayout="column" fxLayoutGap="10px" [formGroup]="noteForm" #noteForm="ngForm">
@ViewChild('noteForm', { static: true }) noteForm: NgForm;
//to reset form
this.noteForm.resetForm();
<button type="reset">Reset</button>
<div [formGroup]="form">
<input placeholder="description..." type="text" formControlName="description" ><br/><br/>
<div
*ngIf="form.get('description').hasError('required') && (form.get('description').dirty || form.get('description').touched) ">
description is required
</div>
<button type="button" (click)="insertNote()">Add for (let control in this.form.controls) {
this.form.controls[control].setErrors(null);
}