Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(input): don't invoke viewChangeListeners before real user input #9913

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2122,13 +2122,18 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$

function writeToModelIfNeeded() {
if (ctrl.$modelValue !== prevModelValue) {
ctrl.$$writeModelToScope();
ctrl.$$writeModelToScope(prevModelValue);
}
}
};

this.$$writeModelToScope = function() {
this.$$writeModelToScope = function(oldVal) {
ngModelSet(ctrl.$modelValue);
// String input types can transform a value into a string without touching it.
if (oldVal != null && !isNaN(oldVal) &&
ctrl.$modelValue === oldVal.toString()) {
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we still change the scope value, the only difference is we don't invoke change listeners. @petebacondarwin you get to review this one and decide if it's worth fixing.

}
forEach(ctrl.$viewChangeListeners, function(listener) {
try {
listener();
Expand Down
12 changes: 12 additions & 0 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,18 @@ describe('input', function() {
});


it('should not invoke viewChangeListeners before input is touched', function() {
scope.value = 1;
var change = scope.change = jasmine.createSpy('change');
var element = $compile('<div><div ng-repeat="i in [1]">' +
'<input type="text" ng-model="value" maxlength="1" ng-change="change()" />' +
'</div></div>')(scope);
scope.$digest();
expect(change).not.toHaveBeenCalled();
dealoc(element);
});


describe('compositionevents', function() {
it('should not update the model between "compositionstart" and "compositionend" on non android', inject(function($sniffer) {
$sniffer.android = false;
Expand Down