Save on (focusout) with angular mat-autocomplete

后端 未结 1 421
被撕碎了的回忆
被撕碎了的回忆 2021-01-25 18:04

I have a simple input with autocomplete



   <         


        
相关标签:
1条回答
  • 2021-01-25 18:45

    If you ONLY want to handle the clicking on autocomplete option you should use (click) on that option to handle it.

    <input [matAutocomplete]="auto">
    <mat-autocomplete #auto="matAutocomplete">
       <mat-option (click)="save(number)" *ngFor="let number of numbers" [value]="number">
         {{number}}
       </mat-option>
    </mat-autocomplete>
    

    However, if you want to do it with focus, this will work:

    <input #myInput (focusout)="save(myInput.value)" [matAutocomplete]="auto">
    <mat-autocomplete #auto="matAutocomplete">
       <mat-option *ngFor="let number of numbers" [value]="number">
         {{number}}
       </mat-option>
    </mat-autocomplete>
    

    Stackblitz

    0 讨论(0)
提交回复
热议问题