orizens / ngx-typeahead

A simple but yet powerful typeahead component for Angular (css framework agnostic)
https://www.npmjs.com/package/ngx-typeahead
MIT License
61 stars 29 forks source link

Clear value after select #34

Closed troncomputers closed 5 years ago

troncomputers commented 5 years ago

Hi! I'm not sure what I'm doing wrong but I want to clear search input after item select. Setting this.search = '' is not clearing the input. Is there a different way?

<input
    style="width:100%;border-radius:15px;text-align:center"
    placeholder="Wyszukaj towar..."
    class="form-control"
    [value]="search"
    [taItemTpl]="itemTmpl"
    ngxTypeahead
    [taList]="products"
    (taSelected)="handleResultSelected($event)"
    (click)="selectText($event)"
/>
  handleResultSelected(result) {
    this.selectedProduct = result;
    this.selectedProduct.twr_Ilosc = 1;
    this.ngxSmartModal.getModal('myModal').open();
  }
  addSelectedProduct() {
    if (!this.editMode) {
      this.selectedProducts.push(this.selectedProduct);
    } else {
      this.editMode = false;
    }
    this.documentCounter();
    this.search = '';
  }
akashjobanputra commented 5 years ago

@troncomputers Did you figured out a solution for that? I'm looking for the same thing.

akashjobanputra commented 5 years ago

@troncomputers Clearing the value in setTimeout gets the job done, reasons unknown. Ex:

setTimeout(() => { this.search = '' });
troncomputers commented 5 years ago

I had this problem almost a year ago. I'm not using ngx-typeahead anymore. I switched to Angular Material.