This article mainly introduces the usage of Angular2 pipeline Pipe and custom pipeline format data. It analyzes the related concepts, syntax and usage skills of Angular2 pipeline and pure pipeline in detail in the form of examples. Friends in need can refer to it
The example in this article describes the usage of Angular2 pipeline Pipe and custom pipe format data. Share it with everyone for your reference, the details are as follows:
Pipe can format data according to the developer's wishes, and can also connect multiple pipes in series.
Pure Pipe and Impure Pipe
Pipeline is divided into Pure Pipe and Impure Pipe (Impure Pipe). By default, pipes are pure. If you set the pure flag to false when declaring a custom pipe, it means that the pipe is not pure. For example:
@Pipe({
name: 'sexReform',
pure:false
})
Copy after login
The difference between pure pipes and non-pure pipes:
①Pure pipe:
Angular only detects pure changes in the input value , pure pipeline will be executed. Pure changes refer to changes in original type values (String,Number,Boolean,Symbol) or changes in object references. (Changes in object values are not pure changes and will not be executed).
② Impure pipeline
Angular will execute impure pipelines in the change detection cycle of each component. Therefore, if we use impure pipes, we have to pay attention to performance issues.
Pipe usage syntax
{{expression | pipe : arg}}
If it is chain concatenation:
{{expression | pipe1 : arg | pipe2 | pipe3 }}
Commonly used built-in pipes
Pipe
Type
Function
##DatePipe
Pure Pipe
Date formatting
JsonPipe
Non-pure pipe
Use JSON.stringify() to convert the object into json characters String
UpperCasePipe
Pure Pipe
Convert all letters in the text to uppercase
LowerCasePipe
Pure Pipe
Convert all letters in the text to lowercase
DecimalPipe
Pure Pipe
Numeric formatting
CurrencyPipe
Pure pipe
Currency formatting
PercentPipe
Pure pipe
Percent formatting
SlicePipe
Non-pure pipe
Array or string cutting
DatePipe
语法:{{expression | date:format}}
expression支持日期对象、日期字符串、毫秒级时间戳。format是指定的格式,常用标志符:
y 年 y使用4位数字表示年份(2017),yy使用两位数字表示(17) M 月 M 1位或两位数字(2或10、11、12),MM 两位数字表示,前面补0(02) d 日 d 一位或两位数字(9) dd两位数字,前面补0(09) E 星期 EEE 三位字母缩写的星期 EEEE 星期全称 j 12小时制时间 j (9 AM) jj (09 AM) h 12小时制小时 h(9) hh (09) H 24小时制小时 H(9) HH (09) m 分 m (5) mm (05) s 秒 s (1) ss (01) z 时区 z China Standard Time
The above is the detailed content of About custom pipe format data usage in Angular2. For more information, please follow other related articles on the PHP Chinese 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