Angularjs:当用户点击enter时更改表格单元格的值
这是我的桌子Angularjs:当用户点击enter时更改表格单元格的值,angularjs,events,angularjs-directive,angularjs-ng-change,Angularjs,Events,Angularjs Directive,Angularjs Ng Change,这是我的桌子 <tr ng-repeat="list in results"> <td>{{list.name}}</td> <td>{{list.id}}</td> <td ng-model="phone" contenteditable on-keydown="myFunction(results)" keys="[13]"> {{list.phone}} </td>
<tr ng-repeat="list in results">
<td>{{list.name}}</td>
<td>{{list.id}}</td>
<td ng-model="phone" contenteditable on-keydown="myFunction(results)" keys="[13]">
{{list.phone}}
</td>
但是当用户输入7890123
然后新的结果是这样的
[name:John, id:123, phone:7890123],[]...
我该怎么做?这是我的指示
编辑:
不要直接将数据挂接到表单,而是尝试将数据放入编辑模型中,然后在方法调用后应用它 这里有一个示例,并不特定于您的案例,但您可以将此方法应用于您的用例。
谢谢。但问题是我如何调用$scope。。。在我的指令里?我不知道怎么做?我添加了我的指令
[name:John, id:123, phone:7890123],[]...
angular.module('myApp').directive('onKeydown', function() {
return function(scope, elm, attrs) {
function applyKeydown() {
scope.$apply(attrs.onKeydown);
};
var allowedKeys = scope.$eval(attrs.keys);
elm.bind('keydown', function(evt) {
if (!allowedKeys || allowedKeys.length == 0) {
applyKeydown();
} else {
angular.forEach(allowedKeys, function(key) {
if (key == evt.which) {
applyKeydown();
}
});
}
});
};
});
});