Overview
In this article, we will see Filters in Angular JS. How they work, and their functionalities with an example.
Do refer to previous articles here.
- Overview Of AngularJS
- Modules And Controller In AngularJS
- Controllers in AngularJS
- AngularJS ng src Directive
- AngularJS ng-Repeat Directive
- Handling Events In AngularJS
- How To Use Two-Way Data Binding In AngularJS
Introduction
Let's see the syntax first to sort the data in AngularJS.To sort the data in Angular JS, we will use order by the filter.
{{ orderby_expression | orderBy : expression : reverse }}
As you can see from the syntax, it has two parameters an expression and the reverse.
NOTE: To sort data in ascending order, set reverse order as false. To sort in descending order, set it as true. You can also use + to sort the data in ascending and – the data in descending order.
Here with the filters in Angular JS, instead of displaying the various rows, we will be sorting it in ascending and descending order.
Now, let's see our model.

var mypartone = angular.module("mymodule", []).controller("myController", function($scope) {
var employees = [{
name: "Akshay",
dateOfBirth: new Date("July 21, 1960"),
Address: "Mumbai",
Salary: "1234.34"
}, {
name: "Milind",
dateOfBirth: new Date("July 20, 1960"),
Address: "Nashik",
Salary: "12.34"
}, {
name: "Raghvan",
dateOfBirth: new Date("July 19, 1960"),
Address: "Pune",
Salary: "1235.34"
}, {
name: "Hari",
dateOfBirth: new Date("July 18, 1960"),
Address: "Mumbai",
Salary: "5589.34"
}];
$scope.employees = employees;
});
Now, similarly, in our view section, we displayed our data as.
<table>
<thead>
<tr>
<th>Name</th>
<th>Date of Birth</th>
<th>Address</th>
<th>Salary</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employee in employees">
<td>{{ employee.name | uppercase }}</td>
<td>{{ employee.dateOfBirth | date : "dd/MM/yyyy" }}</td>
<td>{{ employee.Address | lowercase }}</td>
<td>{{ employee.Salary | number : 2 }}</td>
<td>{{ employee.Salary | currency }}</td>
</tr>
</tbody>
</table>







Shaili DashoraPosted Jul 24, 2016, 3:55 AM
Nice one
Shobana JPosted Jul 23, 2016, 4:10 AM
Nice sharing
kalu singh raoPosted Jul 23, 2016, 1:39 AM
Nice share
Vignesh ManiPosted Jul 22, 2016, 5:29 PM
Nice