Filters are used to change or modify the data. These can be clubbed in expression or directives using pipe (|) character.

A list of some common filters and their usage is given below.

Filter NameDescription
Uppercaseconverts a text to uppercase text.
Lowercaseconverts a text to lowercase text.
Currencyformats text in currency format.
Filterfilter the array to a subset of it based on certain conditions.
OrderbyOrders the array based on certain conditions.
DateFormat a date to a specified format.
JsonFormat an object to a JSON String.
NumberFormat number to a string.
LimitToLimits an array or string into a specified number of elements or characters.

1. Example of Uppercase and Lowercase filters.
  1. <!DOCTYPE html>
  2. <html ng-app="myApp">
  3. <head>
  4. <scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js">
  5. </script>
  6. <title></title>
  7. <meta charset="utf-8" /> </head>
  8. <body>
  9. <div ng-controller="MyCtrl"> My Name is {{firstName|uppercase}} {{lastName|lowercase}} </div>
  10. <script>
  11. var app = angular.module("myApp", []);
  12. app.controller("MyCtrl", function($scope) {
  13. $scope.firstName = "Rohit",
  14. $scope.lastName = "Singh"
  15. });
  16. </script>
  17. </body>
  18. </html>
Output

My Name is ROHIT singh.

2. Example of Currency filter.
  1. <input type="text" ng-model="salary" />
  2. Salary entered by you is: {{salary | currency }}
Output

Salary entered by you is: $145.00.

3. Example of Custom Filter.
  1. <!DOCTYPE html>
  2. <html ng-app="myApp">
  3. <head>
  4. <scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js">
  5. </script>
  6. <title></title>
  7. <meta charset="utf-8" /> </head>
  8. <body>
  9. <div ng-controller="MyCtrl">
  10. <ul>
  11. <li ng-repeat="name in names | filter:'y'"> {{name}} </li>
  12. </ul>
  13. </div>
  14. <script>
  15. var app = angular.module("myApp", []);
  16. app.controller("MyCtrl", function($scope) {
  17. $scope.names = ['Ankush', 'Vinay', 'Saurav', 'Sandeep', 'Gaurav', 'Sanjay', 'Akshay', ];
  18. });
  19. </script>
  20. </body>
  21. </html>
Output
  • Vinay
  • Sanjay
  • Akshay
The above code only shows the names of those students who have letter 'Y' in their name.