简体   繁体   中英

mat-autocomplete prevent input update

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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