AngularJS Filters

Filters are used to change the output data. Suppose, a form asks a user to enter his name, date-of-birth, monthly salary, and a field with 50 characters maximum, etc., it is a good practice to follow a standard format for each. Date-of-birth in the format mm/dd/yyyy and currency in the form of $111.11 gives a consistent look . Filters can be used to filter the output data in required format.

Filters can be used with expressions or directives. Filters are prefixed by a pipe symbol ‘|’. This can be understood as the left expression to the | is being changed to the right format.

Usage: {{ data |  filter  : options }}

Filters can also be used with arguments or by chaining the filters.

List of filters

  • | currency – changes the data to a currency format

  • | date – can be used for mm/dd/yyyy format.

  • | uppercase – to change the data to uppercase

  • | lowercase – to change the data to lower case

  • | limitTo – to limit the number of characters to a specific number of letters

  • | orderBy – to order the output data in ascending / descending order.

For Example : Sample AngularJS Filters

Previous
Previous

AngularJS Form Validations

Next
Next

The ng- thing