MCPcopy Index your code
hub / github.com/angular-ui/ui-router / setupModelWatcher

Function setupModelWatcher

test/angular/1.6/angular.js:30092–30117  ·  view source on GitHub ↗
(ctrl)

Source from the content-addressed store, hash-verified

30090};
30091
30092function setupModelWatcher(ctrl) {
30093 // model -> value
30094 // Note: we cannot use a normal scope.$watch as we want to detect the following:
30095 // 1. scope value is 'a'
30096 // 2. user enters 'b'
30097 // 3. ng-change kicks in and reverts scope value to 'a'
30098 // -> scope value did not change since the last digest as
30099 // ng-change executes in apply phase
30100 // 4. view should be changed back to 'a'
30101 ctrl.$$scope.$watch(function ngModelWatch(scope) {
30102 var modelValue = ctrl.$$ngModelGet(scope);
30103
30104 // if scope model value and ngModel value are out of sync
30105 // This cannot be moved to the action function, because it would not catch the
30106 // case where the model is changed in the ngChange function or the model setter
30107 if (modelValue !== ctrl.$modelValue &&
30108 // checks for NaN is needed to allow setting the model to NaN when there's an asyncValidator
30109 // eslint-disable-next-line no-self-compare
30110 (ctrl.$modelValue === ctrl.$modelValue || modelValue === modelValue)
30111 ) {
30112 ctrl.$$setModelValue(modelValue);
30113 }
30114
30115 return modelValue;
30116 });
30117}
30118
30119/**
30120 * @ngdoc method

Callers 1

NgModelControllerFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected