mat-autocomplete prevent input update

Viewed 15

Is there a solution to prevent mat-autocomplete from updating the input on optionSelect ?

the goal is to obtain a list of suggestions after the user types some input and when the user selects one element from the dropdown hide the dropdown, leave the input with the same value and execute some arbitrary action with the selected element data

1 Answers

my solution was to patch the MatAutocompleteTrigger

   @ViewChild(MatAutocompleteTrigger) auto!: MatAutocompleteTrigger;

   ngAfterViewInit() {
    const auto = this.auto;
    auto._setValueAndClose = (event: any)=>{
      auto.closePanel()
      console.log(event.source._mostRecentViewValue)
    }
  }
Related