Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
30-Mar-2025Understanding 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: