问题描述
我有一个type="number"
输入,它与一个ng-model相关联.我希望能够按下上下箭头来更新其值.但是在这种情况下,在Microsoft Edge中ng-model不会更新,请在此处查看我的示例:
I have a input with type="number"
, it is associated with a ng-model.I want to be able to press up and down arrows to update its value. However in Microsoft Edge the ng-model is not updated in this case, see my example here:
https://plnkr.co/edit/yZaGxkYG87C1YCNSKnf0?p=preview
是否有一种不使用jquery来更新模型的方法?我们要避免在控制器中使用jquery
Is there a way of updating the model, that's not using jquery? We want to avoid using jquery in controllers
推荐答案
因此,这是angularjs和Edge的一个错误,如以下讨论所示:
So it's a bug from both angularjs and Edge, as seen in the discussion below:
https://github.com/angular/angular.js/issues/15366
提出了一个片段来自行解决问题:
A snippet is proposed to fix the problem by oneself:
.directive('input', () => {
if(currentBrowser!="edge") return {};
return {
link: (scope, elem) => {
if (elem[0].type === 'number') {
elem.on('keydown', evt => {
switch (evt.which) {
case 38: // UP_ARROW
case 40: // DOWN_ARROW
scope.$evalAsync(() => elem.triggerHandler('change'));
break;
}
});
}
}
};
});
这篇关于Microsoft Edge和Angularjs:ng-model不适用于输入数字类型和箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!