Home  >  Article  >  php教程  >  A brief analysis of angular's $filter service

A brief analysis of angular's $filter service

高洛峰
高洛峰Original
2016-12-07 10:09:111395browse

First, let’s introduce the $filter service:

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

2. AngularJS has built-in currency, date, filter, json, limitTo, lowercase, uppercase, number, orderBy These 8 filters;

3. Filters can be nested and separated by pipe symbols "|" (a bit like Linux);

4. Filters can pass parameters;

5. Users can customize filters.

Introducing the built-in filters:

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

date: Format date, it provides rich date formats.

json: Complete json formatting.

number: Such as converting to two decimal places, etc.

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:39AM
2011-05-03 06:39:08
$30.00

Customized filter:

eg:

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

Use: {{ 'JennyLin' | myFilter }}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn