Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (21 sloc) 1.24 KB
title author layout lang ref permalink path tags
Parsers y Formatters Angularjs
Marcelo Carmona
post
en
parsers-and-formatters
parsers-and-formatters
2015-10-16-parsers-and-formatters.md
Angularjs
JavaScript

$parsers

It is an array of functions to execute. These functions are executed in order like a pipeline every time that the control read a DOM value. Functions are called following the order of the array and the result of the function is the entry of the next function and the last return value is sent to the collection of $validators

If the parser returns undefined that means that an error occurred, $validators are not going to be executed and the ngModel is going to be seted undefined unless ngModelOptions.allowInvalid is set to true the parse error is stored in ngModel. $ error.parse

$formatters

It is an array of functions that are executed in the pipeline when the ngModel change, the functions are called in reverse order, and each one passes its value back to the next. The last value returned is used as a value in the DOM

In the following image, it can be seen that the parsers are used to transform the data from the view to the model and the formatters of the model to the view