Home  >  Article  >  Web Front-end  >  Detailed explanation of common pipeline examples in Angular4

Detailed explanation of common pipeline examples in Angular4

小云云
小云云Original
2018-05-11 16:43:052430browse

Usually we need to use pipes to format data. The pipes in Angular4 have some changes from before. This article mainly introduces the commonly used pipelines in Angular4. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.

1. Case conversion pipeline

  • uppercase converts the string to uppercase

  • lowercase Convert the string to lowercase

<p>将字符串转换为大写{{str | uppercase}}</p>
str:string = &#39;hello&#39;

will be displayed on the page

Convert the string to uppercase HELLO

2. Date Pipe

date. The date pipe character can accept parameters to specify the format of the output date.

<p>现在的时间是{{today | date:&#39;yyyy-MM-dd HH:mm:ss&#39;}}</p>
today:Date = new Date();

The page will show that the current time is 10:57:53 on May 8, 2017

3. Decimal Pipeline

number The pipeline is used to process numbers into the decimal format we need

The received parameter format is {minimum number of integer digits}.{minimum number of decimal digits}-{maximum number of decimal digits}

The minimum number of integer digits defaults to 1

The minimum number of decimal digits defaults to 0

The maximum number of decimal digits defaults to 3

When the number of decimal places is less than the specified {minimum number of decimal places}, 0 will be added automatically

When the number of decimal places is more than the specified {maximum number of decimal places}, it will be Rounding

<p>圆周率是{{pi | number:&#39;2.2-4&#39;}}</p>
pi:number = 3.14159;

will be displayed on the page

The pi is 03.1416

4. Currency Pipe

The currency pipe is used Convert the number to currency format

<p>{{a | currency:&#39;USD&#39;:false}}</p>
<p>{{b | currency:&#39;USD&#39;:true:&#39;4.2-2&#39;}}</p>
a:number = 8.2515
b:number = 156.548

The page will display

USD8.25

0156.55 'USD' here is the abbreviation of United States dollar, When it is false, the symbol is not displayed. When it is true, the $ symbol is displayed. The following parameters specifying the number of decimal places are the same as those introduced above.

Related recommendations:

Application of PHP multi-threaded pipeline communication

The above is the detailed content of Detailed explanation of common pipeline examples in Angular4. For more information, please follow other related articles on the PHP Chinese website!

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