[FIXED] How to turn a keyup event into a click button using angular


I have a input field with a working keyup event, and I need to turn the icon into a button, so when the user clicks on it, it applies the filter. This is my HTML:

<input type="text"
 (keyup)="applyFilterOrgReach($event.target.value, countries, 500)"
  <i class="fas fa-search search-icon"></i>

And my component.ts:

applyFilterOrgReach(filterValue: string, values: MatTableDataSource<any[]>, debounceTime: number) {
    this.organizationReachSearchParam = filterValue.trim().toLocaleLowerCase();
    setTimeout(() => {
      if (filterValue === null) {
        values.filter = '';
      } else {
        values.filter = this.organizationReachSearchParam;
      this.globalRegions = this.getGlobalRegions(this.countries.filteredData);
    }, debounceTime);


You can pass the input value in click event and use the existing method in ts same as yours.

<input type="text"
     matInput #input
      <i class="fas fa-search search-icon" (click)="applyFilterOrgReach(input.value, countries, 500)"></i>

Answered By – perumal N

Answer Checked By – Robin (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published