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

Commit 0cb87f9

Browse files
deanapetersonpetebacondarwin
authored andcommitted
docs(ngModelController): improve $parsers/$formatters with example
1 parent 6ca5272 commit 0cb87f9

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/ng/directive/input.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,12 +813,21 @@ var VALID_CLASS = 'ng-valid',
813813
*
814814
* @property {string} $viewValue Actual string value in the view.
815815
* @property {*} $modelValue The value in the model, that the control is bound to.
816-
* @property {Array.<Function>} $parsers Whenever the control reads value from the DOM, it executes
817-
* all of these functions to sanitize / convert the value as well as validate.
818-
*
819-
* @property {Array.<Function>} $formatters Whenever the model value changes, it executes all of
820-
* these functions to convert the value as well as validate.
816+
* @property {Array.<Function>} $parsers Array of functions to execute, as a pipeline, whenever
817+
the control reads value from the DOM. Each function is called, in turn, passing the value
818+
through to the next. Used to sanitize / convert the value as well as validation.
821819
*
820+
* @property {Array.<Function>} $formatters Array of functions to execute, as a pipeline, whenever
821+
the model value changes. Each function is called, in turn, passing the value through to the
822+
next. Used to format / convert values for display in the control and validation.
823+
* <pre>
824+
* function formatter(value) {
825+
* if (value) {
826+
* return value.toUpperCase();
827+
* }
828+
* }
829+
* ngModel.$formatters.push(formatter);
830+
* </pre>
822831
* @property {Object} $error An object hash with all errors as keys.
823832
*
824833
* @property {boolean} $pristine True if user has not interacted with the control yet.

0 commit comments

Comments
 (0)