简体   繁体   English

mat-autocomplete 面板在 Angular 中打开表单加载

[英]mat-autocomplete panel opening on form load in Angular

The first autocomplete control's selection panel is opened when I open modal dialog and I am trying to close the panel as shown below:当我打开模态对话框时,第一个自动完成控件的选择面板被打开,我试图关闭面板,如下所示:

html: 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: TS:

//@ViewChild('autoCompleteInput', { read: MatAutocompleteTrigger }) autoComplete: MatAutocompleteTrigger; 
// I also tried this
@ViewChild(MatAutocompleteTrigger) autoCompleteInput: MatAutocompleteTrigger;

ngAfterViewInit() {
  debugger;
  this.autoCompleteInput.closePanel();
}

But unfortunately the first autocomplete's panel is opened on dialog load.但不幸的是,第一个自动完成面板是在对话框加载时打开的。 How can I prevent the panel opened or if it is not possible, close the panel?如何防止面板打开,或者如果不可能,关闭面板?

just give只是给

autoFocus:false 

this.dialog.open(yourcomponent,{
autoFocus:false
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM