angular – 如何捕获NgbTypeahead SelectedItemEvent?

前端之家收集整理的这篇文章主要介绍了angular – 如何捕获NgbTypeahead SelectedItemEvent?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想从typeahead上选择项目选择运行一些自定义逻辑.我无法使用typeahead控件绑定选定的项事件.我正在使用ng-bootstrap(bootstrap4).

<input type="text" [(ngModel)]="model" [ngbTypeahead]="search" placeholder="Search" [resultTemplate]="rt"  [inputFormatter]="formatter" />

解决方法

您可以绑定到ngbTypeahead的selectItem输出

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

这将在你的组件类中:

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

这是一个工作的plunker:plunker

猜你在找的Angularjs相关文章