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

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(ngModel): allow setting model to NaN when asyncValidator is present
Closes #11315
Closes #11411
  • Loading branch information
Narretz authored and petebacondarwin committed Apr 3, 2015
1 parent 830c81d commit b64519f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ng/directive/ngModel.js
Expand Up @@ -810,7 +810,10 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$

// if scope model value and ngModel value are out of sync
// TODO(perf): why not move this to the action fn?
if (modelValue !== ctrl.$modelValue) {
if (modelValue !== ctrl.$modelValue &&
// checks for NaN is needed to allow setting the model to NaN when there's an asyncValidator
(ctrl.$modelValue === ctrl.$modelValue || modelValue === modelValue)
) {
ctrl.$modelValue = ctrl.$$rawModelValue = modelValue;
parserValid = undefined;

Expand Down
23 changes: 23 additions & 0 deletions test/ng/directive/ngModelSpec.js
Expand Up @@ -578,6 +578,29 @@ describe('ngModel', function() {

dealoc(form);
}));


it('should set NaN as the $modelValue when an asyncValidator is present',
inject(function($q) {

ctrl.$asyncValidators.test = function() {
return $q(function(resolve, reject) {
resolve();
});
};

scope.$apply('value = 10');
expect(ctrl.$modelValue).toBe(10);

expect(function() {
scope.$apply(function() {
scope.value = NaN;
});
}).not.toThrow();

expect(ctrl.$modelValue).toBeNaN();

}));
});


Expand Down

0 comments on commit b64519f

Please sign in to comment.