我想在下面的文本框中捕捉回车键按下事件。为了使它更清楚我使用ng重复填充tbody。这里是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']);
我使用一个资源来填充表,我的控制器代码是:
function Ajaxy($scope,$resource) { //controller which has resource to populate the table }
你需要添加一个指令,像这样:
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>