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);
}
}
...
}