Home > OS >  Is there a way to call a function when no longer hovering mat-option in Angular?
Is there a way to call a function when no longer hovering mat-option in Angular?

Time:05-21

I was given the following code

<mat-form-field appearance="fill" style="margin: 0px 20px;font-size:13px;">
          <input matInput type="text" aria-label="Number" placeholder="{{'Home.search' | translate }}"
            [formControl]="myControl" [matAutocomplete]="auto" (ngModelChange)="getByKeyword($event)">

<mat-option *ngFor="let testCity of testCities" [value]="testCity.city"
    (click)="testFunction(testCity.city, testCity.countryIso, testCity.cityId)">

I want to know, is there a way to call "testFunction" without (click) but instead with something that detects that the input field is no longer hovered or with each instance of new letter typed?

CodePudding user response:

Use "mouseleave" event (same use as "click") to execute function on stop hover. For detecting typing you can use "keydown" or "keyup" events.

  • Related