Home > php教程 > PHP开发 > body text

A brief analysis of angular's $filter service

高洛峰
Release: 2016-12-07 10:09:11
Original
1436 people have browsed it

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 }}
Copy after login

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;
}
});
Copy after login

Use: {{ 'JennyLin' | myFilter }}


Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template