Angular Pipes
A pipe transforms a value for display, right inside the template. You write the value, a vertical bar |, and the pipe name: {{ price | currency }}. The underlying data stays untouched — only what the user sees changes.
Using built-in pipes
Pipes are standalone classes from @angular/common, so you import the ones you use:
import { Component } from '@angular/core';
import { CurrencyPipe, DatePipe, DecimalPipe, PercentPipe, UpperCasePipe, TitleCasePipe } from '@angular/common';
@Component({
selector: 'app-invoice',
imports: [CurrencyPipe, DatePipe, DecimalPipe, PercentPipe, UpperCasePipe, TitleCasePipe],
template: `
<p>Client: {{ client | titlecase }}</p>
<p>Code: {{ code | uppercase }}</p>
<p>Issued: {{ issued | date: 'mediumDate' }}</p>
<p>Amount: {{ amount | currency: 'EUR' }}</p>
<p>Hours: {{ hours | number: '1.1-1' }}</p>
<p>Discount: {{ discount | percent }}</p>
`,
})
export class Invoice {
client = 'green leaf studio';
code = 'inv-2025-031';
issued = new Date(2025, 2, 14);
amount = 1249.5;
hours = 37.25;
discount = 0.15;
}Pipe parameters
Arguments follow the pipe name, separated by colons: {{ value | pipe: arg1 : arg2 }}.
| Pipe | Example | Output |
|---|---|---|
date |
d | date: 'yyyy-MM-dd' |
2025-03-14 |
date |
d | date: 'shortTime' |
9:05 AM |
currency |
9.5 | currency: 'USD' : 'symbol' : '1.0-0' |
$10 |
number |
3.14159 | number: '1.2-2' |
3.14 |
percent |
0.256 | percent: '1.1-1' |
25.6% |
slice |
'Angular' | slice: 0 : 3 |
Ang |
json |
obj | json |
pretty-printed JSON (great for debugging) |
keyvalue |
obj | keyvalue |
array of { key, value } for @for |
async |
obs$ | async |
latest value of an Observable or Promise |
The number format '1.2-2' means minimum integer digits . minimum fraction digits - maximum fraction digits.
What pipes do internally
The formatting pipes use the browser's internationalisation API under the hood. You can produce similar results with Intl in plain TypeScript:
const eur = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'EUR' });
const oneDecimal = new Intl.NumberFormat('en-US', { minimumFractionDigits: 1, maximumFractionDigits: 1 });
const pct = new Intl.NumberFormat('en-US', { style: 'percent' });
const medium = new Intl.DateTimeFormat('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
console.log(eur.format(1249.5));
console.log(oneDecimal.format(37.25));
console.log(pct.format(0.15));
console.log(medium.format(new Date(2025, 2, 14)));€1,249.50
37.3
15%
Mar 14, 2025
Chaining pipes
The output of one pipe can feed the next. They are applied left to right:
import { Component } from '@angular/core';
import { DatePipe, UpperCasePipe, SlicePipe } from '@angular/common';
@Component({
selector: 'app-chain',
imports: [DatePipe, UpperCasePipe, SlicePipe],
template: `
<p>{{ launch | date: 'fullDate' | uppercase }}</p>
<p>{{ tagline | slice: 0 : 20 | uppercase }}…</p>
`,
})
export class Chain {
launch = new Date(2025, 10, 20);
tagline = 'The web framework that scales with your team';
}Iterating an object with keyvalue
@for works on arrays, so to loop over an object's entries pipe it through keyvalue first. Entries are sorted by key:
import { Component } from '@angular/core';
import { KeyValuePipe } from '@angular/common';
@Component({
selector: 'app-stock',
imports: [KeyValuePipe],
template: `
<ul>
@for (entry of stock | keyvalue; track entry.key) {
<li>{{ entry.key }}: {{ entry.value }}</li>
}
</ul>
`,
})
export class Stock {
stock = { pears: 12, apples: 40, mangoes: 7 };
}Tip: Pipes are pure by default — Angular re-runs them only when the input value (or an argument) changes, so they are cheaper than calling a formatting method from the template on every check.
Test yourself
What does {{ 0.42 | percent }} display?
- 0.42%
- 42%
- 4.2%
- 0.42
How do you pass two arguments to a pipe?
value | pipe(a, b)value | pipe: a : bvalue | pipe[a][b]pipe(value, a, b)
In what order are chained pipes {{ x | a | b }} applied?
- b first, then a
- a first, then b
- In parallel
- Only the last pipe runs