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

Commit d00ed40

Browse files
committed
add docs
1 parent fe465cd commit d00ed40

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

src/ng/directive/ngModel.js

+57-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,50 @@ 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+
* 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+
*/
900956
$setModelValue: function(modelValue) {
901957
this.$modelValue = this.$$rawModelValue = modelValue;
902958
this.$$parserValid = undefined;

0 commit comments

Comments
 (0)