当我打开模态对话框并尝试关闭面板时,将打开第一个自动完成控件的选择面板,如下所示:
html:
<mat-form-field>
<input
#autoCompleteInput
matInput
type="text"
[matAutocomplete]="auto"
>
<mat-autocomplete #auto="matAutocomplete" autoActiveFirstOption="true" [displayWith]="displayFn">
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
{{option.name}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
ts:
//@ViewChild('autoCompleteInput', { read: MatAutocompleteTrigger }) autoComplete: MatAutocompleteTrigger;
// I also tried this
@ViewChild(MatAutocompleteTrigger) autoCompleteInput: MatAutocompleteTrigger;
ngAfterViewInit() {
debugger;
this.autoCompleteInput.closePanel();
}
但不幸的是,第一个自动完成的面板是在对话框加载时打开的。如何防止面板打开,或者如果不可能,关闭面板?