这是我的桌子
<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>
用户可以编辑电话号码并按回车键。如何将 list.phone 的值更新为新输入的值?因此,例如最初的结果如下所示
[name:John, id:123, phone:123456],[]....
但是当用户输入时7890123
,新结果看起来像这样
[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();
}
});
}
});
};
});
});