Angular 如何将窗体控件重置为原始状态?

Angular 如何将窗体控件重置为原始状态?,angular,Angular,如果我有下面的表单控件 <mat-form-field class="example-full-width"> <input matInput placeholder="First Name" type="text" class="form-control" name="firstName" [(ngModel)]="firstName"> </mat-form-field> 如何将其状态从组件重置回ng pristine?这将在您的表单中将每个

如果我有下面的表单控件

<mat-form-field class="example-full-width">
    <input matInput placeholder="First Name" type="text" class="form-control" name="firstName" [(ngModel)]="firstName">
</mat-form-field>


如何将其状态从组件重置回ng pristine?

这将在您的表单中将每个ngModel标记为pristine。如果您想将pristine标记为一个特定的,只需在forEach循环中添加一个条件

class//bla bla bla bla{
@ViewChildren(NgModel)字段:QueryList;
//东西
checkErrors(){
this.fields.forEach(模型=>{
model.control.markAsPristine();
}

};
它找不到我的字段(我使用[formFroup]和formControlName)。@ViewChildren不仅可用于NgModel,因此您可以为您的FormGroup指定html标识符