@@ -731,11 +731,6 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
731
731
$exceptionHandler ( e ) ;
732
732
}
733
733
} ) ;
734
- if ( ctrl . $viewChangeListeners . length > 0 ||
735
- ctrl . $options && ctrl . $options . getterSetter === true
736
- ) {
737
- modelToViewAction ( ngModelGet ( $scope ) ) ;
738
- }
739
734
} ;
740
735
741
736
/**
@@ -825,13 +820,19 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
825
820
}
826
821
} ;
827
822
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'
829
831
$scope . $watch ( function ngModelWatch ( ) {
830
- return ngModelGet ( $scope ) ;
831
- } , ngModelWatchAction , ctrl . $options && ctrl . $options . deepWatch ) ;
832
+ var modelValue = ngModelGet ( $scope ) ;
832
833
833
- function ngModelWatchAction ( modelValue ) {
834
834
// if scope model value and ngModel value are out of sync
835
+ // TODO(perf): why not move this to the action fn?
835
836
if ( modelValue !== ctrl . $modelValue &&
836
837
// checks for NaN is needed to allow setting the model to NaN when there's an asyncValidator
837
838
( ctrl . $modelValue === ctrl . $modelValue || modelValue === modelValue )
@@ -854,7 +855,9 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
854
855
ctrl . $$runValidators ( modelValue , viewValue , noop ) ;
855
856
}
856
857
}
857
- }
858
+
859
+ return modelValue ;
860
+ } ) ;
858
861
} ] ;
859
862
860
863
0 commit comments