AngularJS basic knowledge note filter _ AngularJS

Source: Internet
Author: User
In our development, the information displayed on the page must be formatted to be displayed to the user. For example, time localization, or yyyy-MM-ddHH: mm: ss format, numeric precision formatting, localization, name formatting, and so on. In angularjs, the filter command is provided for us, so that we can easily implement the function filters of some columns to change and modify data, and can be classified into expressions or using MPs queue instructions. The following is a list of commonly used filters.

S. No. name description
1. convert uppercase text to uppercase text.
2. convert lowercase text to lowercase text.
3. text in the format of currency and currency.
4. the filter filters a subset of the array based on the provided standard.
5. sort and sort basic arrays. Capital filter

Add an upper-case filter to use the MPs queue expression. Here, an upper-case filter is added to print all student names in upper-case letters.

Enter first name:Enter last name: Name in Upper Case: {{student.fullName() | uppercase}}

Lower case filter

Add a lower-case filter using the MPs queue expression. Add a lower-case filter to print the student name with lower-case letters.

Enter first name:Enter last name: Name in Upper Case: {{student.fullName() | lowercase}}

Currency filter

The expression of the number returned by the coin filter using the MPs queue. Here, we have added a filter for printing the cost of currency format.

Enter fees: fees: {{student.fees | currency}}

Filter

To display only the required topics, we use subjectName as the filter.

Enter subject: Subject:
 
 
  • {{ subject.name + ', marks:' + subject.marks }}

Sort filter

To sort topics by tag, we use orderBy tag.

Subject:

 
 
  • {{ subject.name + ', marks:' + subject.marks }}

Example

The following example shows all the above filters.

TestAngularJS.html

Angular JS FiltersAngularJS Sample Application

Enter first name:
Enter last name:
Enter fees:
Enter subject:

Name in Upper Case: {Student. fullName () | uppercase }}
Name in Lower Case: {Student. fullName () | lowercase }}
Fees: {Student. fees | currency }}
Subject:
  • {Subject. name + ', marks:' + subject. marks }}

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

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.