How do filters work in AngularJS, and can you create a custom filter?
Ask by ICSM Computer
Updated 30 Mar 2025
Understanding Filters in AngularJS
Filters in AngularJS are used to format data before displaying it in the UI. They can be used in expressions, directives (
ng-repeat,ng-model, etc.), and controllers.1. Built-in Filters
AngularJS provides several built-in filters, such as:
currencydateuppercase/lowercaselimitToorderByfilter2. Creating a Custom Filter
You can create a custom filter using the
.filter()method in an AngularJS module.Example: Capitalize the First Letter
Step 1: Define the Filter
Step 2: Use in HTML
3. Custom Filter with Parameters
You can pass additional arguments to a custom filter.
Example: Custom Filter to Append a String
Filter Definition
Usage in HTML
4. Custom Filter for Filtering Arrays
Filters can also modify arrays dynamically.
Example: Filter Even Numbers
Filter Definition
Usage in HTML
5. Performance Consideration
ng-repeatfor large lists, as they get re-evaluated every digest cycle. Instead, pre-process the data in the controller: