O'Reilly logo

Mastering Web Application Development with AngularJS by Pawel Kozlowski, Peter Bacon Darwin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling model transformations with filters

AngularJS expressions can get fairly complex and contain function invocations. Those functions might serve different purposes but model transformations and formatting are common needs. To cater for those common use-cases AngularJS expressions support special formatting (transforming) functions called filters:

{{user.signedUp| date:'yyyy-MM-dd'}}

In this example the date filter is used to format user's sign-up date.

A filter is nothing more than a global, named function that is invoked in view using the pipe (|) symbol with parameters separated by the colon (:) character. In fact we could re-write our sample code like so (provided that the formatDate function is defined on a scope):

{{formatDate(user.signedUp ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required