SlideShare a Scribd company logo
Build in Filters 
A filter formats the value of an expression for display to the user. They can be used in view templates, controllers or 
services and it is easy to define your own filter. 
In Other word you can say, a filter provides a way to format the data we display to the user. Angular gives us 
Several built-in filters as well as an easy way to create our own. 
We invoke filters in our HTML with the | (pipe) character inside the template binding characters {{ 
}}. 
Example 1 
external.js 
//defining module 
var app = angular.module('IG', []) 
app.controller('FirstController', ['$scope', function ($scope) { 
$scope.customers = [ 
{ 
name: 'David', 
street: '1234 Anywhere St.' 
}, 
{ 
name: 'Tina', 
street: '1800 Crest St.' 
}, 
{ 
name: 'Brajesh', 
street: 'Noida' 
}, 
{ 
name: 'Michelle', 
street: '890 Main St.' 
} 
]; 
} ]) 
Index.html 
<!DOCTYPE html> 
<html ng-app="IG"> 
<head lang="en"> 
<meta charset="UTF-8"> 
<title>Filter in AngularJS</title> 
<script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"> 
</script> 
<script src="Scripts/external.js"></script> 
</head> 
<body> 
<div ng-controller="FirstController"> 
<input type="text" ng-model="SearchData" /> 
<ul>
<li ng-repeat="Cust in customers | filter:SearchData | orderBy: ‘Name’"> 
{{Cust.name}} - {{Cust.street}} 
</li> 
</ul> 
</div> 
</body> 
</html> 
Example 2 
external.js 
//defining module 
var app = angular.module('IG', []) 
app.controller('SecondController', ['$scope', function ($scope) { 
$scope.friends = 
[{name:'John', phone:'555-1212', age:10}, 
{name:'Mary', phone:'555-9876', age:19}, 
{name:'Mike', phone:'555-4321', age:21}, 
{name:'Adam', phone:'555-5678', age:35}, 
{name:'Julie', phone:'555-8765', age:29}]; 
$scope.predicate = '-age'; 
} ]) 
index.html 
<!DOCTYPE html> 
<html ng-app="IG"> 
<head lang="en"> 
<meta charset="UTF-8"> 
<title>Filter in AngularJS</title> 
<script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"> 
</script> 
<script src="Scripts/external.js"></script> 
</head> 
<body> 
<div ng-controller="SecondController"> 
<pre>Sorting predicate = {{predicate}}; reverse = {{reverse}}</pre> 
<hr/> 
[ <a href="" ng-click="predicate=''">unsorted</a> ] 
<table class="friend"> 
<tr> 
<th><a href="" ng-click="predicate = 'name'; reverse=false">Name</a> 
(<a href="" ng-click="predicate = '-name'; reverse=false">^</a>)</th> 
<th><a href="" ng-click="predicate = 'phone'; reverse=!reverse">Phone 
Number</a></th> 
<th><a href="" ng-click="predicate = 'age'; reverse=!reverse">Age</a></th> 
</tr> 
<tr ng-repeat="friend in friends | orderBy:predicate:reverse"> 
<td>{{friend.name}}</td> 
<td>{{friend.phone}}</td> 
<td>{{friend.age}}</td>
</tr> 
</table> 
</div> 
</body> 
</html> 
Example 3 
external.js 
//defining module 
var app = angular.module('IG', []) 
app.controller('FirstController', ['$scope', function ($scope) { 
$scope.customers = [ 
{ 
name: 'David', 
street: '1234 Anywhere St.' 
}, 
{ 
name: 'Tina', 
street: '1800 Crest St.' 
}, 
{ 
name: 'Brajesh', 
street: 'Noida' 
}, 
{ 
name: 'Michelle', 
street: '890 Main St.' 
} 
]; 
} ]) 
Index.html 
<!DOCTYPE html> 
<html ng-app="IG"> 
<head lang="en"> 
<meta charset="UTF-8"> 
<title>Filter in AngularJS</title> 
<script 
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"> 
</script> 
<script src="Scripts/external.js"></script> 
</head> 
<body> 
<div ng-controller="FirstController"> 
<input type="text" ng-model="SearchData" /> 
<ul> 
<li ng-repeat="Cust in customers | filter:SearchData | orderBy: ‘Name’ | 
LimitTo:5"> 
{{Cust.name}} - {{Cust.street}} 
</li> 
</ul> 
</div>
</body> 
</html> 
Example 4 
How to pass multiple parameter at same time in filter 
<strong>{{PeerWorstValue | sliderchangevalue:UnitId:Decimal_Place}}</strong> 
app.filter('sliderchangevalue', function () { 
return function (value, uid, DP) { 
var uuid = uid; 
if (uuid == 2) { 
var strValue = "" + value; 
var arr = strValue.replace("-", "").split(".")[0].split(""); 
//console.log(arr); 
if (arr.length >= 12) { 
value = strValue / 1000000000000; 
return value.toFixed(DP) + "T"; 
} 
else if (arr.length >= 9) { 
value = strValue / 1000000000; 
return value.toFixed(DP) + "B"; 
} 
else if (arr.length >= 6) { 
value = strValue / 1000000; 
return value.toFixed(DP) + "M"; 
} 
else if (arr.length >= 3) { 
value = strValue / 1000; 
return value.toFixed(DP) + "K"; 
} 
else { 
return value.toFixed(DP); 
} 
} 
else 
return value.toFixed(DP); 
}; 
});

More Related Content

DOCX
Controller in AngularJS
DOCX
Filters in AngularJS
PPTX
AngularJS Introduction
DOCX
Understanding angular js $rootscope and $scope
DOCX
Directives
DOCX
Shaping up with angular JS
PPTX
AngularJS Directives
PPTX
AngularJS in 60ish Minutes
Controller in AngularJS
Filters in AngularJS
AngularJS Introduction
Understanding angular js $rootscope and $scope
Directives
Shaping up with angular JS
AngularJS Directives
AngularJS in 60ish Minutes

What's hot (20)

PPTX
Building an End-to-End AngularJS Application
PPTX
Why angular js Framework
PPTX
Angular Js Basics
PPTX
Angular js PPT
PPTX
Angular js for beginners
PDF
Angular js routing options
PPTX
Practical AngularJS
PPTX
Understanding angular js
PPTX
Angular directive filter and routing
PPTX
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
PPTX
Dart and AngularDart
PDF
AngularJS Basic Training
PDF
AngularJS: an introduction
PDF
Introduction to AngularJS
PPTX
AngularJS Beginners Workshop
PPTX
Angular js
PPTX
The AngularJS way
PPTX
Angular JS - Introduction
PDF
Advanced Tips & Tricks for using Angular JS
PPTX
Angular js architecture (v1.4.8)
Building an End-to-End AngularJS Application
Why angular js Framework
Angular Js Basics
Angular js PPT
Angular js for beginners
Angular js routing options
Practical AngularJS
Understanding angular js
Angular directive filter and routing
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
Dart and AngularDart
AngularJS Basic Training
AngularJS: an introduction
Introduction to AngularJS
AngularJS Beginners Workshop
Angular js
The AngularJS way
Angular JS - Introduction
Advanced Tips & Tricks for using Angular JS
Angular js architecture (v1.4.8)
Ad

Similar to Built in filters (20)

PDF
Angular js - 4developers 12 kwietnia 2013
PDF
Workshop 12: AngularJS Parte I
PDF
Introduction to AngularJS
PDF
Introduction to angular js
PDF
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
PPTX
Optimizing Angular Performance in Enterprise Single Page Apps
PPTX
AngularJS
PPT
AngularJS Mobile Warsaw 20-10-2014
PPT
Jquery.Tmpl
PDF
Pengenalan AngularJS
PDF
ANGULARJS.pdf
PPTX
Angular js
PPTX
Basics of AngularJS
PDF
Get AngularJS Started!
PPTX
Valentine with AngularJS
PPTX
Angular Workshop_Sarajevo2
PDF
Angular.js is super cool
PDF
Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
PPTX
AngularJS for Java Developers
PPTX
AngularJs Workshop SDP December 28th 2014
Angular js - 4developers 12 kwietnia 2013
Workshop 12: AngularJS Parte I
Introduction to AngularJS
Introduction to angular js
AngularJS in 60ish Minutes - Dan Wahlin | FalafelCON 2014
Optimizing Angular Performance in Enterprise Single Page Apps
AngularJS
AngularJS Mobile Warsaw 20-10-2014
Jquery.Tmpl
Pengenalan AngularJS
ANGULARJS.pdf
Angular js
Basics of AngularJS
Get AngularJS Started!
Valentine with AngularJS
Angular Workshop_Sarajevo2
Angular.js is super cool
Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
AngularJS for Java Developers
AngularJs Workshop SDP December 28th 2014
Ad

Recently uploaded (20)

PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Complications of Minimal Access Surgery at WLH
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Classroom Observation Tools for Teachers
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Basic Mud Logging Guide for educational purpose
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
RMMM.pdf make it easy to upload and study
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Institutional Correction lecture only . . .
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Anesthesia in Laparoscopic Surgery in India
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Complications of Minimal Access Surgery at WLH
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Classroom Observation Tools for Teachers
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Basic Mud Logging Guide for educational purpose
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Week 4 Term 3 Study Techniques revisited.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
RMMM.pdf make it easy to upload and study
O5-L3 Freight Transport Ops (International) V1.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Institutional Correction lecture only . . .
VCE English Exam - Section C Student Revision Booklet
Final Presentation General Medicine 03-08-2024.pptx
Pharma ospi slides which help in ospi learning
2.FourierTransform-ShortQuestionswithAnswers.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Anesthesia in Laparoscopic Surgery in India

Built in filters

  • 1. Build in Filters A filter formats the value of an expression for display to the user. They can be used in view templates, controllers or services and it is easy to define your own filter. In Other word you can say, a filter provides a way to format the data we display to the user. Angular gives us Several built-in filters as well as an easy way to create our own. We invoke filters in our HTML with the | (pipe) character inside the template binding characters {{ }}. Example 1 external.js //defining module var app = angular.module('IG', []) app.controller('FirstController', ['$scope', function ($scope) { $scope.customers = [ { name: 'David', street: '1234 Anywhere St.' }, { name: 'Tina', street: '1800 Crest St.' }, { name: 'Brajesh', street: 'Noida' }, { name: 'Michelle', street: '890 Main St.' } ]; } ]) Index.html <!DOCTYPE html> <html ng-app="IG"> <head lang="en"> <meta charset="UTF-8"> <title>Filter in AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"> </script> <script src="Scripts/external.js"></script> </head> <body> <div ng-controller="FirstController"> <input type="text" ng-model="SearchData" /> <ul>
  • 2. <li ng-repeat="Cust in customers | filter:SearchData | orderBy: ‘Name’"> {{Cust.name}} - {{Cust.street}} </li> </ul> </div> </body> </html> Example 2 external.js //defining module var app = angular.module('IG', []) app.controller('SecondController', ['$scope', function ($scope) { $scope.friends = [{name:'John', phone:'555-1212', age:10}, {name:'Mary', phone:'555-9876', age:19}, {name:'Mike', phone:'555-4321', age:21}, {name:'Adam', phone:'555-5678', age:35}, {name:'Julie', phone:'555-8765', age:29}]; $scope.predicate = '-age'; } ]) index.html <!DOCTYPE html> <html ng-app="IG"> <head lang="en"> <meta charset="UTF-8"> <title>Filter in AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"> </script> <script src="Scripts/external.js"></script> </head> <body> <div ng-controller="SecondController"> <pre>Sorting predicate = {{predicate}}; reverse = {{reverse}}</pre> <hr/> [ <a href="" ng-click="predicate=''">unsorted</a> ] <table class="friend"> <tr> <th><a href="" ng-click="predicate = 'name'; reverse=false">Name</a> (<a href="" ng-click="predicate = '-name'; reverse=false">^</a>)</th> <th><a href="" ng-click="predicate = 'phone'; reverse=!reverse">Phone Number</a></th> <th><a href="" ng-click="predicate = 'age'; reverse=!reverse">Age</a></th> </tr> <tr ng-repeat="friend in friends | orderBy:predicate:reverse"> <td>{{friend.name}}</td> <td>{{friend.phone}}</td> <td>{{friend.age}}</td>
  • 3. </tr> </table> </div> </body> </html> Example 3 external.js //defining module var app = angular.module('IG', []) app.controller('FirstController', ['$scope', function ($scope) { $scope.customers = [ { name: 'David', street: '1234 Anywhere St.' }, { name: 'Tina', street: '1800 Crest St.' }, { name: 'Brajesh', street: 'Noida' }, { name: 'Michelle', street: '890 Main St.' } ]; } ]) Index.html <!DOCTYPE html> <html ng-app="IG"> <head lang="en"> <meta charset="UTF-8"> <title>Filter in AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"> </script> <script src="Scripts/external.js"></script> </head> <body> <div ng-controller="FirstController"> <input type="text" ng-model="SearchData" /> <ul> <li ng-repeat="Cust in customers | filter:SearchData | orderBy: ‘Name’ | LimitTo:5"> {{Cust.name}} - {{Cust.street}} </li> </ul> </div>
  • 4. </body> </html> Example 4 How to pass multiple parameter at same time in filter <strong>{{PeerWorstValue | sliderchangevalue:UnitId:Decimal_Place}}</strong> app.filter('sliderchangevalue', function () { return function (value, uid, DP) { var uuid = uid; if (uuid == 2) { var strValue = "" + value; var arr = strValue.replace("-", "").split(".")[0].split(""); //console.log(arr); if (arr.length >= 12) { value = strValue / 1000000000000; return value.toFixed(DP) + "T"; } else if (arr.length >= 9) { value = strValue / 1000000000; return value.toFixed(DP) + "B"; } else if (arr.length >= 6) { value = strValue / 1000000; return value.toFixed(DP) + "M"; } else if (arr.length >= 3) { value = strValue / 1000; return value.toFixed(DP) + "K"; } else { return value.toFixed(DP); } } else return value.toFixed(DP); }; });