@@ -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,49 @@ 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
+ * However, when the $viewValue or the rendered DOM value of the control should be updated
946
+ * after a user input, this method can be used. For example, consider a text input
947
+ * with an autocomplete list for countries. A user enters `ge` and then selects `Germany` from
948
+ * the list. The autocomplete widget will call $setViewValue({label: 'Germany', id: 'de'}),
949
+ * but the rendered value will still be `ge`. For the model -> view pipeline, the widget
950
+ * adds a formatter that extracts the label from the object.
951
+ * The widget can then call ctrl.$setModelValue(ctrl.$modelValue) to run the model -> view
952
+ * pipeline again and render `Germany` in the DOM.
953
+ *
954
+ */
900
955
$setModelValue : function ( modelValue ) {
901
956
this . $modelValue = this . $$rawModelValue = modelValue ;
902
957
this . $$parserValid = undefined ;
0 commit comments