ngBootstrap捕获有关提前输入建议的点击事件

时间:2019-02-14 11:57:04

标签: css angular6 ng-bootstrap

当我键入'ala'时,它会在建议“ 阿拉巴马”和“ 阿拉斯加”中显示2个状态。现在我需要的是,一旦我单击“ alaska” /“ alabama”,列表中的任何项目都应调用我的方法

methodAbc(){
   //Some complex logic
   alert("Method called.");
} 

示例代码链接click here

我在文本框上尝试了模糊,聚焦等事件,但它们没有按我需要的方式工作。单击不触发项目选择,当我在文本框内单击时触发。

1 个答案:

答案 0 :(得分:1)

您只需要使用ng-bootstrap的ngbTypeAhead API中的selectItem事件

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

请参见updated sample code