AngularJS filters:-
Filters are used to change modify the data and can be clubbed in expression or directives using pipe character.
Filters in angular can do 3 different things
Filters can be used with a binding expression or a directive To apply a filter use pipe (|) character
Syntax:-
limitTo filter:- Can be used to limit the number of rows or characters in a string. Syntax:-
Example:- First create javascript file and give name Script.js as following:
Demo.html page
Out Put: Browse the Demo.html and get the out put as shown in below image:
Filters in angular can do 3 different things
- Format data
- Sort data
- Filter data
Filters can be used with a binding expression or a directive To apply a filter use pipe (|) character
Syntax:-
{{ expression | filterName:parameter }}
limitTo filter:- Can be used to limit the number of rows or characters in a string. Syntax:-
{{ expression | limitTo : limit : begin}}
Example:- First create javascript file and give name Script.js as following:
var app = angular .module("myModule", []) .controller("myController", function ($scope) { var employees = [ { name: "Santosh Kumar Singh", dateOfBirth: new Date("October 5, 1991"), gender: "Male", salary: 59000 }, { name: "Reena Kumari", dateOfBirth: new Date("May 02, 1990"), gender: "Female", salary: 70000.325 }, { name: "Chandan Kumar", dateOfBirth: new Date("August 25, 1991"), gender: "Male", salary: 55000 }, { name: "Gagan Agrawal", dateOfBirth: new Date("October 2, 1991"), gender: "Female", salary: 50000 }, { name: "Shubha", dateOfBirth: new Date("December 30, 1989"), gender: "Female", salary: 78000 }, { name: "Anu Singh", dateOfBirth: new Date("December 28, 1988"), gender: "Female", salary: 62000 } ]; $scope.employees = employees; $scope.rowCount = 3; });
Demo.html page
AngularJS filters Demo:
Rows to display :
Name Date of Birth Gender Salary (number filter) Salary (currency filter) {{ employee.name | uppercase }} {{ employee.dateOfBirth | date:"dd/MM/yyyy" }} {{ employee.gender }} {{ employee.salary | number:2 }} {{ employee.salary | currency : "£" : 1 }}
Out Put: Browse the Demo.html and get the out put as shown in below image: