我有一个简单的观点;
<form ng-submit="ctrl.check()">
<input type="text" ng-model="ctrl.input">
</form>
<div>
<span ng-repeat="input in ctrl.log">{{input}}<br></span>
</div>
连接到控制器;
app.controller('verify', [..., function(...) {
var ctrl = this;
// some variables omitted here
ctrl.input = '';
ctrl.log = [];
ctrl.check = function()
{
ctrl.log.unshift(ctrl.input);
// some logic omitted here
};
}]);
但是当用户扫描包含字符串&#34; 123456789.
&#34;的条形码时反复地,日志对象包含随机裁剪的值。
从截图中,我看到了这一点:
12345678
1234567
123
在记事本中扫描条形码非常有效。
我很难看到这里发生了什么,但我唯一怀疑的是,ng-model绑定在更新模型时比表单响应enter键要慢,从而导致提交到在模型更新之前发生。
这是一个有角度的已知问题/有谁知道如何防止这种情况发生?