@@ -731,6 +731,11 @@ 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
+ }
734
739
} ;
735
740
736
741
/**
@@ -820,19 +825,13 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
820
825
}
821
826
} ;
822
827
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'
828
+ // model -> view
831
829
$scope . $watch ( function ngModelWatch ( ) {
832
- var modelValue = ngModelGet ( $scope ) ;
830
+ return ngModelGet ( $scope ) ;
831
+ } , ngModelWatchAction , ctrl . $options && ctrl . $options . deepWatch ) ;
833
832
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?
836
835
if ( modelValue !== ctrl . $modelValue &&
837
836
// checks for NaN is needed to allow setting the model to NaN when there's an asyncValidator
838
837
( ctrl . $modelValue === ctrl . $modelValue || modelValue === modelValue )
@@ -855,9 +854,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
855
854
ctrl . $$runValidators ( modelValue , viewValue , noop ) ;
856
855
}
857
856
}
858
-
859
- return modelValue ;
860
- } ) ;
857
+ }
861
858
} ] ;
862
859
863
860
0 commit comments