Filters are used to change the modified data and can be classified in expressions or using pipe characters directives. Below is a list of commonly used filters.
| S.No. | name | describe |
|---|---|---|
| 1 | capital | Convert text to uppercase text. |
| 2 | lower case | Convert text to lowercase text. |
| 3 | currency | Currency format text. |
| 4 | Filter | Filter an array of subsets it is based on the provided criteria. |
| 5 | Sort | Sort provides standard basic arrays. |
Caps filter
Add uppercase filters to use expressions of pipe characters. Here, capital filters are added, and students' names are printed in 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 filters, using expressions of pipe characters. Add a lowercase filter here to print student names in lowercase 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() | lowercase}}Currency filter
The Canadian dollar filter uses a pipe character to return the expression of the number. Here we have added filters to the printing fee of currency using currency format.
Enter fees: <input type="text" ng-model="student.fees">fees: {{student.fees | currency}}Filters for filters
To display only the desired topics, we use subjectName as the filter.
Enter subject: <input type="text" ng-model="subjectName">Subject:<ul> <li ng-repeat="subject in student.subjects | filter: subjectName"> {{ subject.name + ', marks:' + subject.marks }} </li></ul>Sort filter
To sort topics by tags, we use orderBy tags.
Subject:<ul> <li ng-repeat="subject in student.subjects | orderBy:'marks'"> {{ subject.name + ', marks:' + subject.marks }} </li></ul>example
The following examples will show all the filters mentioned above.
testAngularJS.html
<html><head><title>Angular JS Filters</title></head><body><h2>AngularJS Sample Application</h2><div ng-app="" ng-controller="studentController"><table><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><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></tr></tr><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> <li ng-repeat="subject in student.subjects | filter: subjectName |orderBy:'marks'"> {{ subject.name + ', marks:' + subject.marks }} </li></ul></td></tr></table></div><script>function studentController($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><script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script></body></html>Output
Open textAngularJS.html in a web browser and see the following results:
The above is the information sorting out the AngularJS filter. We will continue to add relevant information in the future. Thank you for your support for this site!