简体   繁体   English

AngularJs Bootstrap提前输入检测在Enter键上触发的事件

[英]AngularJs Bootstrap typeahead detect event fired on enter key

I have an angular bootstrap typeahead and the code is as given below. 我提前输入了一个角引导程序,代码如下。

Html : HTML:

<div class="col-sm-12 dlg-zero-margin-padding hide-last-result" align="left">
    <input type="text" id="myInput" 
        ng-model="selected" 
        ng-keyup="myKeyUp(event,this.value)"
        typeahead="item for item in filterInput($viewValue)"
        typeahead-on-select='onSelect($item)'>                       
</div>

My controller 我的控制器

$scope.myKeyUp(event, value) {
    debugger;
}
$scope.onSelect(event, value) {
    debugger;
}

When mouse focus is on any of the typeahead options, my onSelect function is invoked regardless of mouse click or enter key press. 当鼠标焦点位于任何一个预输入选项上时,无论单击鼠标还是按下Enter键,都会调用我的onSelect函数。 IE it is called whenever a selection is made. IE即在进行选择时被调用。 But I want to differentiate between a mouse click and enter key selection as I want to add some different flow in each case. 但是我想区分鼠标单击和输入键选择,因为我想在每种情况下添加一些不同的流程。

How can I invoke 2 separate functions on enter key press and on mouse click. 如何在Enter键和鼠标单击时调用2个单独的函数。 Or can I detect enter key press or a mouse click in my onSelect function? 还是可以在onSelect函数中检测到回车键或鼠标单击?

Please note : On keyup event(ie myKeyUp()) does not fire when I press "enter". 请注意:当我按下“ enter”键时,在keyup事件(即myKeyUp())不会触发。 Only onSelect function gets invoked. 仅onSelect函数被调用。

inside your function you can identify if enter key is pressed and handle both case 在您的函数内部,您可以确定是否按下Enter键并处理两种情况

$scope.onSelect(event, value) {
if(event.which ===13){
//enter is pressed
}else{
debugger;
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM