Skip to content

How cool are AngularJS $formatters and $parsers?

Updated: at 12:01 AM

I’m using a model parser to allow inputs to accept dollar signs and commas while the model sees Number values

Cameron Spear writes:

Angular has this concept in directives called $parsers and $formatters. It’s mechanism to be able to format data from model to view so that it’s presented in a more human-friendly way to the user, and when they modify it, it can be translated back to a more computer-friendly mode. It leverages the ngModel controller to do this.

$parsers/$formatters are an array of actions that take in input, translate it to either the computer-friendly or human-friendly format respectively and return the translated value.

Read more from the source: Cameron Spear