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

Commit 18f784c

Browse files
committedMar 24, 2015
fix(ngModel): allow setting model to NaN when asyncValidator is present
1 parent afd0807 commit 18f784c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed
 

‎src/ng/directive/ngModel.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,9 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
810810

811811
// if scope model value and ngModel value are out of sync
812812
// TODO(perf): why not move this to the action fn?
813-
if (modelValue !== ctrl.$modelValue) {
813+
if (modelValue !== ctrl.$modelValue &&
814+
(modelValue === modelValue || ctrl.$modelValue === ctrl.$modelValue)
815+
) {
814816
ctrl.$modelValue = ctrl.$$rawModelValue = modelValue;
815817
parserValid = undefined;
816818

‎test/ng/directive/ngModelSpec.js

+24
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,30 @@ describe('ngModel', function() {
578578

579579
dealoc(form);
580580
}));
581+
582+
583+
it('should set NaN as the $modelValue when an asyncValidator is present',
584+
inject(function($q) {
585+
586+
ctrl.$asyncValidators.test = function() {
587+
return $q(function(resolve, reject) {
588+
resolve();
589+
});
590+
};
591+
592+
scope.$apply('value = 10');
593+
expect(ctrl.$modelValue).toBe(10);
594+
595+
expect(function() {
596+
scope.$apply(function() {
597+
scope.value = NaN;
598+
});
599+
}).not.toThrowMinErr('$rootScope', 'infdig', '10 $digest() iterations reached. Aborting!\n' +
600+
'Watchers fired in the last 5 iterations: []');
601+
602+
expect(ctrl.$modelValue).toBeNaN();
603+
604+
}));
581605
});
582606

583607

0 commit comments

Comments
 (0)