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

Commit 3af71be

Browse files
committed
Revert "refactor(ngModel): move model -> view update from watchFn to watchAction"
This reverts commit 862c9d8. The commit was accidentially pushed. Sorry for the noise.
1 parent f2724b2 commit 3af71be

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/ng/directive/ngModel.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,6 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
731731
$exceptionHandler(e);
732732
}
733733
});
734-
if (ctrl.$viewChangeListeners.length > 0 ||
735-
ctrl.$options && ctrl.$options.getterSetter === true
736-
) {
737-
modelToViewAction(ngModelGet($scope));
738-
}
739734
};
740735

741736
/**
@@ -825,13 +820,19 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
825820
}
826821
};
827822

828-
// model -> view
823+
// model -> value
824+
// Note: we cannot use a normal scope.$watch as we want to detect the following:
825+
// 1. scope value is 'a'
826+
// 2. user enters 'b'
827+
// 3. ng-change kicks in and reverts scope value to 'a'
828+
// -> scope value did not change since the last digest as
829+
// ng-change executes in apply phase
830+
// 4. view should be changed back to 'a'
829831
$scope.$watch(function ngModelWatch() {
830-
return ngModelGet($scope);
831-
}, ngModelWatchAction, ctrl.$options && ctrl.$options.deepWatch);
832+
var modelValue = ngModelGet($scope);
832833

833-
function ngModelWatchAction(modelValue) {
834834
// if scope model value and ngModel value are out of sync
835+
// TODO(perf): why not move this to the action fn?
835836
if (modelValue !== ctrl.$modelValue &&
836837
// checks for NaN is needed to allow setting the model to NaN when there's an asyncValidator
837838
(ctrl.$modelValue === ctrl.$modelValue || modelValue === modelValue)
@@ -854,7 +855,9 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
854855
ctrl.$$runValidators(modelValue, viewValue, noop);
855856
}
856857
}
857-
}
858+
859+
return modelValue;
860+
});
858861
}];
859862

860863

0 commit comments

Comments
 (0)