FormGroupDirective.resetForm() 调用 Observable 事件

问题描述

我在休息角形式时遇到问题。我的打字稿文件中有以下代码 -

@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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...