@@ -31,32 +31,57 @@ var ngModelMinErr = minErr('ngModel');
31
31
* @property {* } $viewValue The actual value from the control's view. For `input` elements, this is a
32
32
* String. See {@link ngModel.NgModelController#$setViewValue} for information about when the $viewValue
33
33
* is set.
34
+ *
34
35
* @property {* } $modelValue The value in the model that the control is bound to.
36
+ *
35
37
* @property {Array.<Function> } $parsers Array of functions to execute, as a pipeline, whenever
36
- the control reads value from the DOM. The functions are called in array order, each passing
37
- its return value through to the next. The last return value is forwarded to the
38
- {@link ngModel.NgModelController#$validators `$validators`} collection.
38
+ * the control updates the ngModelController with a new {@link ngModel.NgModelController#$viewValue
39
+ `$viewValue`} from the DOM, usually via user input.
40
+ See {@link ngModel.NgModelController#$setViewValue `$setViewValue()`} for a detailed lifecycle explanation.
41
+ Note that the `$parsers` are not called when the bound ngModel expression changes programmatically.
39
42
40
- Parsers are used to sanitize / convert the {@link ngModel.NgModelController#$viewValue
41
- `$viewValue`}.
43
+ The functions are called in array order, each passing
44
+ its return value through to the next. The last return value is forwarded to the
45
+ {@link ngModel.NgModelController#$validators `$validators`} collection.
42
46
43
- Returning `undefined` from a parser means a parse error occurred. In that case,
44
- no {@link ngModel.NgModelController#$validators `$validators`} will run and the `ngModel`
45
- will be set to `undefined` unless {@link ngModelOptions `ngModelOptions.allowInvalid`}
46
- is set to `true`. The parse error is stored in `ngModel.$error.parse`.
47
+ Parsers are used to sanitize / convert the {@link ngModel.NgModelController#$viewValue
48
+ `$viewValue`}.
49
+
50
+ Returning `undefined` from a parser means a parse error occurred. In that case,
51
+ no {@link ngModel.NgModelController#$validators `$validators`} will run and the `ngModel`
52
+ will be set to `undefined` unless {@link ngModelOptions `ngModelOptions.allowInvalid`}
53
+ is set to `true`. The parse error is stored in `ngModel.$error.parse`.
54
+
55
+ This simple example shows a parser that would convert text input value to lowercase:
56
+ * ```js
57
+ * function parse(value) {
58
+ * if (value) {
59
+ * return value.toLowerCase();
60
+ * }
61
+ * }
62
+ * ngModelController.$parsers.push(parse);
63
+ * ```
47
64
48
65
*
49
66
* @property {Array.<Function> } $formatters Array of functions to execute, as a pipeline, whenever
50
- the model value changes. The functions are called in reverse array order, each passing the value through to the
51
- next. The last return value is used as the actual DOM value.
52
- Used to format / convert values for display in the control.
67
+ the bound ngModel expression changes programmatically. The `$formatters` are not called when the
68
+ value of the control is changed by user interaction.
69
+
70
+ Formatters are used to format / convert the {@link ngModel.NgModelController#$modelValue
71
+ `$modelValue`} for display in the control.
72
+
73
+ The functions are called in reverse array order, each passing the value through to the
74
+ next. The last return value is used as the actual DOM value.
75
+
76
+ This simple example shows a formatter that would convert the model value to uppercase:
77
+
53
78
* ```js
54
- * function formatter (value) {
79
+ * function format (value) {
55
80
* if (value) {
56
81
* return value.toUpperCase();
57
82
* }
58
83
* }
59
- * ngModel.$formatters.push(formatter );
84
+ * ngModel.$formatters.push(format );
60
85
* ```
61
86
*
62
87
* @property {Object.<string, function> } $validators A collection of validators that are applied
@@ -764,9 +789,10 @@ NgModelController.prototype = {
764
789
*
765
790
* When `$setViewValue` is called, the new `value` will be staged for committing through the `$parsers`
766
791
* and `$validators` pipelines. If there are no special {@link ngModelOptions} specified then the staged
767
- * value sent directly for processing, finally to be applied to `$modelValue` and then the
768
- * **expression** specified in the `ng-model` attribute. Lastly, all the registered change listeners,
769
- * in the `$viewChangeListeners` list, are called.
792
+ * value is sent directly for processing through the `$parsers` pipeline. After this, the `$validators` and
793
+ * `$asyncValidators` are called and the value is applied to `$modelValue`.
794
+ * Finally, the value is set to the **expression** specified in the `ng-model` attribute and
795
+ * all the registered change listeners, in the `$viewChangeListeners` list are called.
770
796
*
771
797
* In case the {@link ng.directive:ngModelOptions ngModelOptions} directive is used with `updateOn`
772
798
* and the `default` trigger is not listed, all those actions will remain pending until one of the
0 commit comments