Filters can be added in AngularJS to format data.
AngularJS provides filters to transform data:
Filters can be added to expressions by using the pipe character |
, followed by a filter.
For example, the uppercase filter converts strings to upper case:
{{ name | uppercase }}
lowercase
filter format strings to lower case:
Filters are added to directives, like ng-repeat
, by using the pipe character |
, followed by a filter.
The currency filter formats a number as currency:
The filter filter can only be used on arrays, and it returns an array containing only the matching items.
Filter an Array Based on User Input
By setting the ng-model directive on an input field, we can use the value of the input field as an expression in a filter.
Type a letter in the input field, and the list will shrink/grow depending on the match: