gpt4 book ai didi

Angular 6 Material form重置使验证错误出现

转载 作者:行者123 更新时间:2023-12-04 02:49:58 24 4
gpt4 key购买 nike

<分区>

当我第一次加载页面时,表单是这样的

enter image description here

但在我成功创建公告后,我使用 this.announcementCreateForm.reset() 代码重置了页面,并通过以下方式重置

enter image description here

我在 ngOnInit() 期间调用了以下方法 buildAnnouncementForm()

 private buildAnnouncementForm() {
this.announcementCreateForm = this.fb.group({
announcementTitle: ['', [Validators.required]],
announcementText: '',
announcementFor: ['', [Validators.required]],
announcementType: ['', [Validators.required]],
announcementFromDate: [this.announcementFromDate, Validators.required],
announcementToDate: [this.announcementToDate, Validators.required]
});
}

我在成功之后调用了reset方法

resetAnnouncementPage() {
if (this.announcementCreateForm.valid) {
console.log("Reset...");
this.announcementCreateForm.reset();
this.announcementCreateForm.markAsPristine();
//this.announcementCreateForm.markAsUntouched();
}
}

我的重置,希望我将表单恢复为加载时的样子。该怎么做?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com