我必须在验证的同时重置我的表单。有什么方法可以将表单状态从 ng-dirty 重置为 ng-pristine。
最佳答案
这是它目前在 Angular 4.1.0 - 5.1.3 中的工作方式:
class YourComponent {
@ViewChild("yourForm")
yourForm: NgForm;
onSubmit(): void {
doYourThing();
// yourForm.reset(), yourForm.resetForm() don't work, but this does:
this.yourForm.form.markAsPristine();
this.yourForm.form.markAsUntouched();
this.yourForm.form.updateValueAndValidity();
}
}
关于angular - 如何在 ANGULAR 2 中提交表单时重置表单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34608361/