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

Commit 807fbf9

Browse files
committed
fix(ngModel): add some info about
1 parent 3aa62d0 commit 807fbf9

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/ng/directive/input.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,9 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
19561956
*
19571957
* @description
19581958
* Runs each of the registered validators (first synchronous validators and then asynchronous validators).
1959+
* If the validity changes to invalid, the model will be set to undefined, unless ngModelOptions.allowInvalid
1960+
* is `true`. If the validity changes to valid, it will set the model to the last available valid
1961+
* modelValue.
19591962
*/
19601963
this.$validate = function() {
19611964
// ignore $validate before model is initialized
@@ -1964,12 +1967,16 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
19641967
}
19651968

19661969
var viewValue = ctrl.$$lastCommittedViewValue;
1967-
var modelValue = ctrl.$rawModelValue;
1970+
var modelValue = ctrl.$$rawModelValue;
1971+
19681972
var prevValid = ctrl.$valid;
19691973
var prevModelValue = ctrl.$modelValue;
1974+
19701975
var allowInvalid = ctrl.$options && ctrl.$options.allowInvalid;
19711976

19721977
ctrl.$$runValidators(undefined, modelValue, viewValue, function(allValid) {
1978+
// If there was no change in validity, don't update the model
1979+
// This prevents changing an invalid modelValue to undefined
19731980
if (!allowInvalid && prevValid !== allValid) {
19741981
// Note: Don't check ctrl.$valid here, as we could have
19751982
// external validators (e.g. calculated on the server),
@@ -2130,7 +2137,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
21302137
}
21312138
var prevModelValue = ctrl.$modelValue;
21322139
var allowInvalid = ctrl.$options && ctrl.$options.allowInvalid;
2133-
ctrl.$rawModelValue = modelValue;
2140+
ctrl.$$rawModelValue = modelValue;
21342141
if (allowInvalid) {
21352142
ctrl.$modelValue = modelValue;
21362143
writeToModelIfNeeded();
@@ -2255,7 +2262,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
22552262
// if scope model value and ngModel value are out of sync
22562263
// TODO(perf): why not move this to the action fn?
22572264
if (modelValue !== ctrl.$modelValue) {
2258-
ctrl.$modelValue = ctrl.$rawModelValue = modelValue;
2265+
ctrl.$modelValue = ctrl.$$rawModelValue = modelValue;
22592266

22602267
var formatters = ctrl.$formatters,
22612268
idx = formatters.length;

0 commit comments

Comments
 (0)