问题描述
@ViewChild('editNgForm',{ static: true }) editNgForm: FormGroupDirective;
officeComposeForm: FormGroup;
ngOnInit(): void {
const officeTypeChanges: Observable<RefData> = this.officeComposeForm.get('officeType').valueChanges;
officeTypeChanges.pipe(takeuntil(this.ngUnsubscribe)).subscribe((officeType: RefData) => {
const selectedEmailTypeCode = this.officeService.getEmailTemplateTypeForofficeTemplate(officeType.code);
this.filteredEmailTemplates = this.emailTemplates.filter(
emailTemplate => emailTemplate.code === selectedEmailTypeCode
);
this.emailTemplateContent = '';
emailContentControl.setValue('');
emailSubjectControl.setValue('');
});
}
rebuildForm() {
if (this.editNgForm) {
this.editNgForm.resetForm();
}
this.filteredEmailTemplates = this.emailTemplates;
this.officeComposeForm.reset();
this.createForm();
}
以及模板中的以下代码 -
<form name="editForm" role="form" [formGroup]="officeComposeForm" #editNgForm="ngForm"
autocomplete="off">
...
<div fxFlex="30" >
<mat-form-field fxFlex>
<mat-label><span jhiTranslate="office.officeType">Office Type</span></mat-label>
<mat-select
id="field_officeType"
formControlName="officeType"
class="search-select"
required
>
<mat-option
[value]="officeType"
*ngFor="let officeType of officeTypes; trackBy: trackById"
>{{ officeType.description }}</mat-option
>
</mat-select>
<mat-error *ngIf="formErrors['officeType']">{{ formErrors['officeType'] | translate }}</mat-error>
</mat-form-field>
</div>
...
</form>
我在点击我的表单时调用 rebuildForm() 函数。 相同的代码也存在于其他形式中,但它不会调用我们在 ngOnInIt 中设置的可观察对象。我试图将“eventEmiter”作为错误参数作为重置表单的一部分传递,但它会传播事件并且我在可观察订阅中获得空值。
this.editNgForm.resetForm({emitEvent:false});
this.officeComposeForm.reset({emitEvent:false});
我期待在表单重置期间不调用任何可观察对象。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)