</>
Skip to content
AngularJS lessons (17/28)

AngularJS — Filters

Built-in Filters

FilterDescription
uppercaseConvert to uppercase
lowercaseConvert to lowercase
currencyFormat as currency
numberFormat as number
dateFormat date
jsonFormat as JSON
limitToLimit array/string
filterFilter array
orderBySort 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

  1. Use built-in filters
  2. Apply multiple filters
  3. Create a custom filter
  4. 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.