Answers for "mat auto complete floating issue"

1

mat auto complete floating issue

//in HTML
<input
  #autoCompleteInput //it is the selector used in component
  type="text"
  class="form-control"
  matInput
  [matAutocomplete]="auto"
  formControlName="country"
  (input)="filterCountries($event.target.value)"
/>

//in component
@ViewChild('autoCompleteInput', { read: MatAutocompleteTrigger, static: false })
autoComplete: MatAutocompleteTrigger;

ngOnInit(): void {
    window.addEventListener('scroll', this.scrollEvent, true);
}

scrollEvent = (event: any): void => {
    if(this.autoComplete.panelOpen)
      // this.autoComplete.closePanel(); //you can also close the panel 
      this.autoComplete.updatePosition();
};
Posted by: Guest on January-26-2022

Code answers related to "TypeScript"

Browse Popular Code Answers by Language