Marcelo Carmona
Published on

Parsers and Formatters Angularjs

Authors

$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