NgbTypeahead selectItem get clicked item ngBootstrap angular2

前端 未结 1 608
温柔的废话
温柔的废话 2020-12-11 01:03

In this answer, it was explained to me to use selectItem to get the select event.

But at this point, the model I bound to the text box is still the original text th

相关标签:
1条回答
  • 2020-12-11 01:17

    You should be using $event to get the selected Items as below

    <input type="text" class="form-control" (selectItem)="selectedItem($event)" [(ngModel)]="model" [ngbTypeahead]="search" [resultFormatter]="formatter" />
    <hr>
    <pre>Model: {{ model | json }}</pre>
    clicked item {{clickedItem}}
    

    Your method should be as

    selectedItem(item){
        this.clickedItem=item.item;
        console.log(item);
      }
    

    LIVE DEMO

    0 讨论(0)
提交回复
热议问题