Skip to content

Commit

Permalink
Cancel previous timeout instead of ignoring events
Browse files Browse the repository at this point in the history
This fixes the IE issue reported to AngularJS at angular#16519

Instead of ignoring key events, we cancel the previous deferred timeout and declare a new one each time. 

This fixes the problem that references to `input` and `origValue` inside the deferred function do not point to the most recent key event occurrence.
  • Loading branch information
thejhh authored Apr 12, 2019
1 parent 55075b8 commit cb2b0fd
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -1349,14 +1349,13 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
element.on('input', listener);
} else {
var deferListener = function(ev, input, origValue) {
if (!timeout) {
timeout = $browser.defer(function() {
timeout = null;
if (!input || input.value !== origValue) {
listener(ev);
}
});
}
if (timeout) $browser.defer.cancel(timeout);
timeout = $browser.defer(function() {
timeout = null;
if (!input || input.value !== origValue) {
listener(ev);
}
});
};

element.on('keydown', /** @this */ function(event) {
Expand Down

0 comments on commit cb2b0fd

Please sign in to comment.