@@ -880,6 +880,24 @@ NgModelController.prototype = {
880
880
this . $options = this . $options . createChild ( options ) ;
881
881
} ,
882
882
883
+ /**
884
+ * @ngdoc method
885
+ *
886
+ * @name ngModel.ngModelController#$format
887
+ *
888
+ * @description
889
+ *
890
+ * Run the ngModel.$formatters on the current $modelValue and
891
+ * set the result to the $viewValue.
892
+ *
893
+ * This method also sets the `ng-empty` or `ng-not-empty`
894
+ * class based on the on the $viewValue.
895
+ *
896
+ * Note that `$render()` must be called to update the DOM
897
+ * of the control with the new $viewValue.
898
+ *
899
+ * @return {mixed } The formatted value.
900
+ */
883
901
$format : function ( ) {
884
902
var formatters = this . $formatters ,
885
903
idx = formatters . length ;
@@ -891,12 +909,50 @@ NgModelController.prototype = {
891
909
892
910
if ( this . $viewValue !== viewValue ) {
893
911
this . $$updateEmptyClasses ( viewValue ) ;
894
- this . $viewValue = this . $lastCommittedViewValue = viewValue ;
912
+ this . $viewValue = this . $$ lastCommittedViewValue = viewValue ;
895
913
}
896
914
897
915
return viewValue ;
898
916
} ,
899
917
918
+ /**
919
+ * @ngdoc method
920
+ *
921
+ * @name ngModel.ngModelController#$setModelValue
922
+ *
923
+ * @param {* } modelValue value from the model.
924
+ *
925
+ * @description
926
+ *
927
+ * Runs the whole model -> view pipeline on the modelValue passed to the
928
+ * function.
929
+ *
930
+ * The modelValue argument should be the same value that is currently set on
931
+ * the scope.
932
+ *
933
+ * The following actions are performed by this method:
934
+ *
935
+ * - the $modelValue is set
936
+ * - the $modelValue is formatted and the result is set to $viewValue
937
+ * - `ng-empty` / `ng-not-empty` is set on the element
938
+ * - if the $viewValue has changed
939
+ * - $render() is called on the control
940
+ * - the `$validators` are run and the validation status is set
941
+ *
942
+ * This method is called by ngModel internally when the bound scope value changes.
943
+ * Application developers usually do not have to call this function themselves.
944
+ *
945
+ * This function can be used when the $viewValue or the rendered DOM value of the control should
946
+ * be updated after a user input.
947
+ * For example, consider a text input with an autocomplete list for countries.
948
+ * A user enters `ge` and then selects `Germany` from the list.
949
+ * Based on this, the autocomplete widget will call $setViewValue({label: 'Germany', id: 'de'}),
950
+ * but the rendered value will still be `ge`.
951
+ * The widget can then call ctrl.$setModelValue(ctrl.$modelValue) to run the model -> view
952
+ * pipeline again, which includes a formatter that converts the object into the string `Germany`
953
+ * which is set to the $viewValue and rendered in the DOM.
954
+ *
955
+ */
900
956
$setModelValue : function ( modelValue ) {
901
957
this . $modelValue = this . $$rawModelValue = modelValue ;
902
958
this . $$parserValid = undefined ;
0 commit comments