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

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Narretz committed Sep 25, 2017
1 parent 8978dd7 commit 4eede61
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion src/ng/directive/ngModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,24 @@ NgModelController.prototype = {
this.$options = this.$options.createChild(options);
},

/**
* @ngdoc method
*
* @name ngModel.ngModelController#$format
*
* @description
*
* Run the ngModel.$formatters on the current $modelValue and
* set the result to the $viewValue.
*
* This method also sets the `ng-empty` or `ng-not-empty`
* class based on the on the $viewValue.
*
* Note that `$render()` must be called to update the DOM
* of the control with the new $viewValue.
*
* @return {mixed} The formatted value.
*/
$format: function() {
var formatters = this.$formatters,
idx = formatters.length;
Expand All @@ -891,12 +909,49 @@ NgModelController.prototype = {

if (this.$viewValue !== viewValue) {
this.$$updateEmptyClasses(viewValue);
this.$viewValue = this.$lastCommittedViewValue = viewValue;
this.$viewValue = this.$$lastCommittedViewValue = viewValue;
}

return viewValue;
},

/**
* @ngdoc method
*
* @name ngModel.ngModelController#$setModelValue
*
* @param {*} modelValue value from the model.
*
* @description
*
* Runs the whole model -> view pipeline on the modelValue passed to the
* function.
*
* The modelValue argument should be the same value that is currently set on
* the scope.
*
* The following actions are performed by this method:
*
* - the $modelValue is set
* - the $modelValue is formatted and the result is set to $viewValue
* - `ng-empty` / `ng-not-empty` is set on the element
* - if the $viewValue has changed
* - $render() is called on the control
* - the `$validators` are run and the validation status is set
*
* This method is called by ngModel internally when the bound scope value changes.
* Application developers usually do not have to call this function themselves.
*
* However, when the $viewValue or the rendered DOM value of the control should be updated
* after a user input, this method can be used. For example, consider a text input
* with an autocomplete list for countries. A user enters `ge` and then selects `Germany` from
* the list. The autocomplete widget will call $setViewValue({label: 'Germany', id: 'de'}),
* but the rendered value will still be `ge`. For the model -> view pipeline, the widget
* adds a formatter that extracts the label from the object.
* The widget can then call ctrl.$setModelValue(ctrl.$modelValue) to run the model -> view
* pipeline again and render `Germany` in the DOM.
*
*/
$setModelValue: function(modelValue) {
this.$modelValue = this.$$rawModelValue = modelValue;
this.$$parserValid = undefined;
Expand Down

0 comments on commit 4eede61

Please sign in to comment.