- AngularJS - Internationalization
- AngularJS - Custom Directives
- AngularJS - Dependency Injection
- AngularJS - Services
- AngularJS - Scopes
- AngularJS - Views
- AngularJS - AJAX
- AngularJS - Includes
- AngularJS - Forms
- AngularJS - Modules
- AngularJS - HTML DOM
- AngularJS - Tables
- AngularJS - Filters
- AngularJS - Controllers
- AngularJS - Expressions
- AngularJS - Directives
- AngularJS - First Application
- AngularJS - MVC Architecture
- AngularJS - Environment Setup
- AngularJS - Overview
- AngularJS - Home
AngularJS Applications
- AngularJS - Lastfm Application
- AngularJS - Leaflet Application
- AngularJS - Timer Application
- AngularJS - Weather Application
- AngularJS - Share Application
- AngularJS - Maps Application
- AngularJS - Chart Application
- AngularJS - Translate Application
- AngularJS - Cart Application
- AngularJS - Drag Application
- AngularJS - Search Tab
- AngularJS - Order Form
- AngularJS - Switch Menu
- AngularJS - Nav Menu
- AngularJS - In-line Application
- AngularJS - Upload File
- AngularJS - Login Application
- AngularJS - Bootstrap Application
- AngularJS - Notepad Application
- AngularJS - ToDo Application
AngularJS Useful Resources
- AngularJS - Discussion
- AngularJS - Useful Resources
- AngularJS - Quick Guide
- AngularJS - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
AngularJS - Filters
Filters are used to modify the data. They can be clubbed in expression or directives using pipe (|) character. The following pst shows the commonly used filters.
Sr.No. | Name & Description |
---|---|
1 | uppercase converts a text to upper case text. |
2 | lowercase converts a text to lower case text. |
3 | currency formats text in a currency format. |
4 | filter filter the array to a subset of it based on provided criteria. |
5 | orderby orders the array based on provided criteria. |
Uppercase Filter
Add uppercase filter to an expression using pipe character. Here we ve added uppercase filter to print student name in all capital letters.
Enter first name:<input type = "text" ng-model = "student.firstName"> Enter last name: <input type = "text" ng-model = "student.lastName"> Name in Upper Case: {{student.fullName() | uppercase}}
Lowercase Filter
Add lowercase filter to an expression using pipe character. Here we ve added lowercase filter to print student name in all lowercase letters.
Enter first name:<input type = "text" ng-model = "student.firstName"> Enter last name: <input type = "text" ng-model = "student.lastName"> Name in Lower Case: {{student.fullName() | lowercase}}
Currency Filter
Add currency filter to an expression returning number using pipe character. Here we ve added currency filter to print fees using currency format.
Enter fees: <input type = "text" ng-model = "student.fees"> fees: {{student.fees | currency}}
Filter
To display only required subjects, we use subjectName as filter.
Enter subject: <input type = "text" ng-model = "subjectName"> Subject: <ul> <p ng-repeat = "subject in student.subjects | filter: subjectName"> {{ subject.name + , marks: + subject.marks }} </p> </ul>
OrderBy Filter
To order subjects by marks, we use orderBy marks.
Subject: <ul> <p ng-repeat = "subject in student.subjects | orderBy: marks "> {{ subject.name + , marks: + subject.marks }} </p> </ul>
Example
The following example shows use of all the above mentioned filters.
testAngularJS.htm
<html> <head> <title>Angular JS Filters</title> <script src = "https://ajax.googleapis.com/ajax/pbs/angularjs/1.3.14/angular.min.js"> </script> </head> <body> <h2>AngularJS Sample Apppcation</h2> <span ng-app = "mainApp" ng-controller = "studentController"> <table border = "0"> <tr> <td>Enter first name:</td> <td><input type = "text" ng-model = "student.firstName"></td> </tr> <tr> <td>Enter last name: </td> <td><input type = "text" ng-model = "student.lastName"></td> </tr> <tr> <td>Enter fees: </td> <td><input type = "text" ng-model = "student.fees"></td> </tr> <tr> <td>Enter subject: </td> <td><input type = "text" ng-model = "subjectName"></td> </tr> </table> <br/> <table border = "0"> <tr> <td>Name in Upper Case: </td><td>{{student.fullName() | uppercase}}</td> </tr> <tr> <td>Name in Lower Case: </td><td>{{student.fullName() | lowercase}}</td> </tr> <tr> <td>fees: </td><td>{{student.fees | currency}} </td> </tr> <tr> <td>Subject:</td> <td> <ul> <p ng-repeat = "subject in student.subjects | filter: subjectName |orderBy: marks "> {{ subject.name + , marks: + subject.marks }} </p> </ul> </td> </tr> </table> </span> <script> var mainApp = angular.module("mainApp", []); mainApp.controller( studentController , function($scope) { $scope.student = { firstName: "Mahesh", lastName: "Parashar", fees:500, subjects:[ {name: Physics ,marks:70}, {name: Chemistry ,marks:80}, {name: Math ,marks:65} ], fullName: function() { var studentObject; studentObject = $scope.student; return studentObject.firstName + " " + studentObject.lastName; } }; }); </script> </body> </html>
Output
Open the file testAngularJS.htm in a web browser. See the result.
Advertisements