css - ngBootstrap 捕获关于提前输入建议的点击事件

标签 css angular6 ng-bootstrap

当我键入 'ala' 时,它会在建议中显示 2 个州 'alabama' 和 'alaska'。现在我需要的是只要我点击“alaska”/“alabama”列表中的任何元素,它就应该调用我的方法

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

示例代码链接 click here

我在文本框上尝试了模糊、聚焦等事件,但它们无法按我需要的方式工作。单击不触发元素选择,它在我单击文本框内部时触发。

最佳答案

您只需要使用来自 ng-bootstrap 的 ngbTypeAhead APIselectItem 事件

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

参见 updated sample code

关于css - ngBootstrap 捕获关于提前输入建议的点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54689863/

相关文章:

javascript - 从 chrome 中的输入类型复选框中删除阴影?

css - 固定和绝对

php - 将多个 css 类分组到另一个类

html - 在 angular6 中执行我的元素时,它只执行 index.html 页面,原因是什么?

javascript - ng bootstrap 4 - typeahead 打开焦点

angular - ng-bootstrap 中轮播的图像缩略图

css - SCSS、 compass 和 GULP : How to minify without breaking CSS?

angular - 在 Angular 6 库中使用 NgRx(带有 ngrx-actions 库)

angular6 - 'IconDefinition' 类型的参数不可分配给 'IconDefinitionOrPack' 类型的参数

angular - Webpack2 Angular2 ng-bootstrap 摇树