AngularJS — Filters
Built-in Filters
| Filter | Description |
|---|---|
| uppercase | Convert to uppercase |
| lowercase | Convert to lowercase |
| currency | Format as currency |
| number | Format as number |
| date | Format date |
| json | Format as JSON |
| limitTo | Limit array/string |
| filter | Filter array |
| orderBy | Sort array |
Usage in Templates
<p>{{name | uppercase}}</p>
<p>{{price | currency:'$'}}</p>
<p>{{today | date:'yyyy-MM-dd'}}</p>
<p>{{data | json}}</p>
<p>{{list | limitTo:5}}</p>
Filter with ng-repeat
<input ng-model="searchText">
<ul>
<li ng-repeat="item in items | filter:searchText | orderBy:'name'">
{{item.name}}
</li>
</ul>
Custom Filter
app.filter('capitalize', function() {
return function(input) {
if (!input) return '';
return input.charAt(0).toUpperCase() + input.slice(1);
};
});
<p>{{name | capitalize}}</p>
Filter in Controller
app.controller('MyController', function($scope, $filter) {
$scope.name = 'john';
$scope.uppercaseName = $filter('uppercase')($scope.name);
});
Mini Practice
- Use built-in filters
- Apply multiple filters
- Create a custom filter
- Use filters in controllers
Up Next
Continue with Custom Filters — creating custom filters.
Related Topics
Frequently Asked Questions about Filters
What is Filters in AngularJS?
Filters is a fundamental concept in AngularJS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Filters?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Filters.
Why is Filters important in AngularJS?
Filters is essential for AngularJS development. Understanding this concept will help you write better code and solve real-world problems more effectively.