在Angularjs中获取ng-keypress上文本框的值

sag*_*r43 8 javascript angularjs

我想在keypress上获取文本框的值.

我有像html的代码

<input style="width: 20%; float: right;" 
       ng-model="que.SelectedOptionsUID" 
       type="text" 
       ng-keypress="myFunct($event)"/>
Run Code Online (Sandbox Code Playgroud)

和控制器上的JS代码:

$scope.myFunct = function (e) {
    var charCode = (e.which) ? e.which : e.keyCode;
    //i want here value of the textbox 
}
Run Code Online (Sandbox Code Playgroud)

dev*_*qon 6

<input style="width: 20%; float: right;" 
       ng-model="que.SelectedOptionsUID" 
       type="text" 
       ng-keypress="myFunct($event, que.SelectedOptionsUID)"/>
Run Code Online (Sandbox Code Playgroud)

控制器:

$scope.myFunct = function (e, myValue) {
    var charCode = (e.which) ? e.which : e.keyCode;        
    // do something with myValue
}
Run Code Online (Sandbox Code Playgroud)

  • 值出现在下一项之后,如果输入“a”,它将出现 null,然后输入“ab”,它将出现“a” (2认同)