问题描述
正如问题所示,我在应用 时遇到问题为
事件. ng2-completer
选择了
As the question suggests, I have a problem applying the selected
event for ng2-completer
.
ng2-completer
似乎也是一个未解决的问题,因为他们尚未发布 Github上的问题.但是,还没有解决方法.
It also seems to be an open issue with ng2-completer
because they haven't released any fix for this issue on Github. However there is no work-around solution yet.
这是我使用的代码.
HTML模板:
<ng2-completer
[(ngModel)]="searchStr"
[datasource]="items"
[minSearchLength]="0"
[openOnFocus]="true"
[placeholder]="'Please enter'"
[textNoResults]="false"
[maxChars]="6"
(keyup)="onKeyDown($event)"
(selected)="onItemSelect($event)"
(blur)="onTouched()">
</ng2-completer>
组件:
onItemSelect(selected: CompleterItem): void {
console.log('selected item');
console.log(selected);
}
当我单击或双击任何项目时,它不会打印任何内容.我也尝试过输入Enter,但是它也不起作用.如果有的话,请帮忙提出解决方案.预先谢谢你.
It doesn't print anything when I click or double click on any item. I've tried typing Enter as well but it also doesn't work. Please help to suggest a work around solution for this if you have. Thank you in advance.
推荐答案
由于ng2-completer在内部实现了ControlValueAccessor,因此可以使用ngModelChange事件发射器来获取发射值.
Since ng2-completer implemented ControlValueAccessor internally, you can use ngModelChange event emitter to get emitted value.
尝试一下:
<ng2-completer
[(ngModel)]="searchStr"
[datasource]="items"
[minSearchLength]="0"
[openOnFocus]="true"
[placeholder]="'Please enter'"
[textNoResults]="false"
[maxChars]="6"
(ngModelChange)="onItemSelect($event)" >
</ng2-completer>
这篇关于ng2-completer选定的事件不会在单击鼠标时触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!