角输入事件仅在IE中触发

时间:2018-11-14 18:29:27

标签: angular internet-explorer angular-material

institutionOnChange输入事件仅在IE11中触发,而不在Chrome中触发。表单控件正在ngOnInit中初始化

<mat-form-field>
  <input matInput required #instititionInput [matAutocomplete]="auto"
      [formControl]="form.get('institution')"
      (input)="institutionOnChange($event)"
      i18n-placeholder placeholder="Institution of Incident"
      i18n-aria-label aria-label="Institution of Incident">

  <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
    <mat-option *ngFor="let institution of filteredInstitutions | async"
        [value]="institution" (onSelectionChange)="institutionSelectionChange($event)">
      {{institution.name}}
    </mat-option>
  </mat-autocomplete>

  <mat-hint *ngIf="form.get('institutionId').hasError('required')" i18n>
    <span class="mat-error">Please choose a institution</span>
  </mat-hint>
</mat-form-field>

问题在于清除更改后的另一个值,直到选中一项为止

institutionOnChange(event) {
  this.form.get('institutionId').setValue('');
}

public ngOnInit() {
  ...
  if (institutionId) {

    const foundInstitution = this.institutions.find(institution => institution.id === institutionId);

    if (foundInstitution) {
      this.form.get('institution').setValue(foundInstitution);
      this.form.get('institutionId').setValue(institutionId);
    }
  }
  ...
}

0 个答案:

没有答案
相关问题