如何使用AngularJS的关键preSS事件? [英] How to use a keypress event in AngularJS?
本文介绍了如何使用AngularJS的关键preSS事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要赶在下面的文本框中输入键preSS事件。为了使它更清楚我使用的是NG-重复填充TBODY。下面是HTML:
I want to catch the enter key press event on the textbox below. To make it more clear I am using a ng-repeat to populate the tbody. Here is the HTML:
<td><input type="number" id="closeqty{{$index}}" class="pagination-right closefield"
data-ng-model="closeqtymodel" data-ng-change="change($index)" required placeholder="{{item.closeMeasure}}" /></td>
这是我的模块:
angular.module('components', ['ngResource']);
我使用的资源来填充表和我的控制器code是:
I am using a resource to populate the table and my controller code is:
function Ajaxy($scope, $resource) {
//controller which has resource to populate the table
}
如果有不再需要的信息,请评论。
If there is anymore info needed, please comment.
推荐答案
您需要添加一个指令
,就像这样:
You need to add a directive
, like this:
的JavaScript
app.directive('myEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.myEnter);
});
event.preventDefault();
}
});
};
});
HTML
<div ng-app="" ng-controller="MainCtrl">
<input type="text" my-enter="doSomething()">
</div>
这篇关于如何使用AngularJS的关键preSS事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文