ANGULARJS filter detailed and sample code _ANGULARJS

Source: Internet
Author: User
Tags lowercase


Filters are used to change the modification data and can be grouped in an expression or by using a pipe character directive. The following is a list of commonly used filters.





s.no. name Description
1 Capital Convert text to uppercase text.
2 Lowercase Convert text to lowercase text.
3 Currency Currency format format text.
4 Filtering device It filters the array according to a subset of the provided criteria.
5 Sort The sort provides a standard base array.





Capital Filter



An expression that adds an uppercase filter using a pipe character. Here, an uppercase filter is added, and all the student names are printed in uppercase letters.


Enter 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 filters



Add a lowercase filter, using an expression for the pipe character. Add a lowercase filter here and print the student's name in lowercase letters.


Enter 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



A currency filter uses an expression that returns a number by a pipe character. Here, we added a filter that currency uses currency format for printing costs.


Enter Fees: <input type= "text" ng-model= "student.fees" >
fees: {{student.fees | currency}}


Filter filter



To display only the topics that you want, we use subjectname as a 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>


Sorting filters



To sort topics by tag, we use the order by sign.


Subject:
<ul>
 <li ng-repeat= "Subject in Student.subjects | By: ' Marks '" >
  {{ Subject.name + ', Marks: ' + subject.marks}}
 </li>
</ul>


Example



The following example shows all of the above filters.



Testangularjs.html


<html>
<head>
<title>Angular JS Filters</title>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app="" 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>
  <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 your Web browser and see the following results:






The above is ANGULARJS filter data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.