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!