@@ -799,6 +799,28 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
799
799
}
800
800
} ;
801
801
802
+ function formatValue ( modelValue ) {
803
+ var formatters = ctrl . $formatters ,
804
+ idx = formatters . length ;
805
+
806
+ var viewValue = modelValue ;
807
+ while ( idx -- ) {
808
+ viewValue = formatters [ idx ] ( viewValue ) ;
809
+ }
810
+
811
+ return viewValue ;
812
+ }
813
+
814
+ this . $runFormatters = function ( ) {
815
+ var modelValue = this . $modelValue ,
816
+ viewValue = formatValue ( this . $modelValue ) ;
817
+
818
+ if ( this . $viewValue !== viewValue ) {
819
+ this . $viewValue = ctrl . $$lastCommittedViewValue = viewValue ;
820
+ this . $render ( ) ;
821
+ }
822
+ } ;
823
+
802
824
// model -> value
803
825
// Note: we cannot use a normal scope.$watch as we want to detect the following:
804
826
// 1. scope value is 'a'
@@ -814,19 +836,11 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
814
836
// TODO(perf): why not move this to the action fn?
815
837
if ( modelValue !== ctrl . $modelValue ) {
816
838
ctrl . $modelValue = ctrl . $$rawModelValue = modelValue ;
839
+ var oldViewValue = ctrl . $viewValue ;
817
840
818
- var formatters = ctrl . $formatters ,
819
- idx = formatters . length ;
820
-
821
- var viewValue = modelValue ;
822
- while ( idx -- ) {
823
- viewValue = formatters [ idx ] ( viewValue ) ;
824
- }
825
- if ( ctrl . $viewValue !== viewValue ) {
826
- ctrl . $viewValue = ctrl . $$lastCommittedViewValue = viewValue ;
827
- ctrl . $render ( ) ;
828
-
829
- ctrl . $$runValidators ( undefined , modelValue , viewValue , noop ) ;
841
+ ctrl . $runFormatters ( ) ;
842
+ if ( ctrl . $viewValue !== oldViewValue ) {
843
+ ctrl . $$runValidators ( undefined , modelValue , ctrl . $viewValue , noop ) ;
830
844
}
831
845
}
832
846
0 commit comments