Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 4eede61

Browse files
committed
add docs
1 parent 8978dd7 commit 4eede61

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

src/ng/directive/ngModel.js

+56-1
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,24 @@ NgModelController.prototype = {
880880
this.$options = this.$options.createChild(options);
881881
},
882882

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+
*/
883901
$format: function() {
884902
var formatters = this.$formatters,
885903
idx = formatters.length;
@@ -891,12 +909,49 @@ NgModelController.prototype = {
891909

892910
if (this.$viewValue !== viewValue) {
893911
this.$$updateEmptyClasses(viewValue);
894-
this.$viewValue = this.$lastCommittedViewValue = viewValue;
912+
this.$viewValue = this.$$lastCommittedViewValue = viewValue;
895913
}
896914

897915
return viewValue;
898916
},
899917

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+
*/
900955
$setModelValue: function(modelValue) {
901956
this.$modelValue = this.$$rawModelValue = modelValue;
902957
this.$$parserValid = undefined;

0 commit comments

Comments
 (0)