Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I capture NgbTypeahead SelectedItemEvent?

I want to run some custom logic on item selection from typeahead. I am unable to bind selected item event with typeahead control. I am using ng-bootstrap (bootstrap4).

<input type="text" [(ngModel)]="model" [ngbTypeahead]="search" placeholder="Search" [resultTemplate]="rt"  [inputFormatter]="formatter" />
like image 468
Cheff Avatar asked Feb 07 '17 17:02

Cheff


1 Answers

You can bind to the selectItem output of the ngbTypeahead

<input type="text" class="form-control" (selectItem)="itemSelected($event)" [(ngModel)]="model" [ngbTypeahead]="search" [resultTemplate]="rt" [inputFormatter]="formatter" />

This would go in your component class:

itemSelected($event) {
    alert($event.item.name);
  }

Here is a working plunker: plunker

like image 145
dmungin Avatar answered Oct 06 '22 00:10

dmungin