Angular Study Notes: angular's $ filter service analysis and angular Study Notes

Source: Internet
Author: User

Angular Study Notes: angular's $ filter service analysis and angular Study Notes

First, we will introduce the $ filter service:

1. $ filter is a dedicated service for formatting data;

2. AngularJS has eight built-in filters: currency, date, filter, json, limitTo, lowercase, uppercase, number, and orderBy;

3. Filters can be nested and separated by the pipeline symbol "|" (a bit like linux );

4. The filter can pass parameters;

5. You can customize the filter.

Introduces the built-in filter:

Currency: used to format the currency, such as automatically adding "$" or "¥" before the value.

Date: format the date. It provides a variety of date formats.

Json: complete json formatting.

Number: such as converting to two decimal places.

OrderBy: sort.

Simple use of filter:

{{ 1304375948024 | date }}{{ 1304375948024 | date:"MM/dd/yyyy h:mma" }}{{ 1304375948024 | date:"yyyy-MM-dd hh:mm:ss" }}{{ 30 | currency }}

Output:

May 3, 2011
05/03/2011 6:39 AM
06:39:08
$30.00

Custom filter:

Eg:

var myModule = angular.module('myModule',[]);myModule.filter('myFilter',function(){return function(item){return 'Hi,'+item;}});

Use: {'jennylin' | myFilter }}

The above content introduces angular's $ filter service in detail. I hope it will be helpful to you. If you have any questions, please leave a message. The editor will reply to you in time!

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.