@@ -799,6 +799,30 @@ 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
+ this . $$runValidators ( undefined , modelValue , viewValue , noop ) ;
823
+ }
824
+ } ;
825
+
802
826
// model -> value
803
827
// Note: we cannot use a normal scope.$watch as we want to detect the following:
804
828
// 1. scope value is 'a'
@@ -815,19 +839,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
815
839
if ( modelValue !== ctrl . $modelValue ) {
816
840
ctrl . $modelValue = ctrl . $$rawModelValue = modelValue ;
817
841
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 ) ;
830
- }
842
+ ctrl . $runFormatters ( ) ;
831
843
}
832
844
833
845
return modelValue ;
0 commit comments