Angular 2. Keyup event not fired from input

andrey.shedko picture andrey.shedko · Jul 15, 2017 · Viewed 10.1k times · Source

Here is very simple situation but I really do not have idea why it's not working. I got input text field that should call function on keyup event. But it's not.

<input class="form-control m-1" type="text" #search (keyup)="filterCatalogues(search.value)">

And the code itself.

filterCatalogues(value: string): CataloguesListDto[] {
    return this.catalogues.filter (catalogue => {
      return catalogue.companyName === value || catalogue.catalogueName === value;
    });
  }

Answer

Jayakrishnan picture Jayakrishnan · Jul 15, 2017

You need to change your filterCatalogues event. I have assumed that catalogues is bound to the dom

<input class="form-control m-1" type="text" #search (keyup)="filterCatalogues()">

filterCatalogues(){
this.catalogues = this.catalogues.filter (catalogue => {
  return catalogue.companyName === searchModel|| catalogue.catalogueName === searchModel;
});
}