我正在使用angular8。我正在寻找一种解决方案,当用户在任何时候关闭弹出式窗体时,我想重置所有显示的错误。
当用户再次单击时,请再次给我一个新的清晰表格。我不知道该怎么办。
这是我的关闭弹出窗口方法:
dismissEditPop() {
this.createForm.reset(); //but not works. before the popup close
this.editPopup = false;
}
这是我的表格验证:
constructor(private formBuilder: FormBuilder) {
this.createForm = this.formBuilder.group({
'Id': new FormControl({ value: 0, disabled: true }, Validators.required),
'Name': ['', Validators.required],
'Discription': ['', Validators.required],
'CreatedBy': ['', Validators.required],
'CreatedDate': new FormControl({ value: 0, disabled: true })
});
}
这是html:
<form [formGroup]="createForm" (ngSubmit)="onCreateFormSubmit()">
<div class="form-group">
<input id="name" type="text"
class="form-control"
formControlName="Name" name="Name"
placeholder="Name">
<div *ngIf="submitted" class="error">
<div *ngIf="f.Name.errors?.required">Name is required</div>
</div>
</div>
<button type="submit" class="btn btn-success" >Create</button>
<button type="button" class="btn btn-default" (click)="dismissEditPop()">Close</button>