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

Commit 948120e

Browse files
Narretzpetebacondarwin
authored andcommitted
fix(ngModel): allow setting model to NaN when asyncValidator is present
Closes #11315 Closes #11411
1 parent 7757f0a commit 948120e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/ng/directive/ngModel.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,10 @@ 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+
// checks for NaN is needed to allow setting the model to NaN when there's an asyncValidator
815+
(ctrl.$modelValue === ctrl.$modelValue || modelValue === modelValue)
816+
) {
814817
ctrl.$modelValue = ctrl.$$rawModelValue = modelValue;
815818
parserValid = undefined;
816819

test/ng/directive/ngModelSpec.js

+23
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,29 @@ 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.toThrow();
600+
601+
expect(ctrl.$modelValue).toBeNaN();
602+
603+
}));
581604
});
582605

583606

0 commit comments

Comments
 (0)