当我键入'ala'时,它会在建议“ 阿拉巴马”和“ 阿拉斯加”中显示2个状态。现在我需要的是,一旦我单击“ alaska” /“ alabama”,列表中的任何项目都应调用我的方法
methodAbc(){
//Some complex logic
alert("Method called.");
}
示例代码链接click here
我在文本框上尝试了模糊,聚焦等事件,但它们没有按我需要的方式工作。单击不触发项目选择,当我在文本框内单击时触发。
答案 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)" />