So far the menu card shows the price 10 with a dollar sign typed into the template by hand, and with no cents. The data is right; only the display isn't tidy yet.
A pipe tidies that display. A pipe changes how a value is shown in the template, without changing the value in the class. A pipe is written after a vertical bar: {{ price | currency:'USD' }}. Picture the receipt printer at the till of Jali's Pancake Stall. In the cash drawer the price stays the number 10. The receipt printer prints it as tidy text, with a dollar sign and two digits for cents. The number in the drawer doesn't change; only the print-out is tidy. In Angular, the number in the drawer is the value in the class, and the receipt printer is the pipe.
Pipes: change the display, not the data
This component uses three built-in pipes:
import { Component } from '@angular/core'
import { CurrencyPipe, DatePipe, UpperCasePipe } from '@angular/common'
@Component({
selector: 'app-root',
standalone: true,
imports: [UpperCasePipe, DatePipe, CurrencyPipe],
template: `
<h3>{{ name | uppercase }}</h3>
<p>{{ price | currency:'USD' }}</p>
<p>{{ time | date:'dd/MM/yyyy HH:mm' }}</p>
`,
})
export class App {
name = 'Special Egg Pancake'
price = 10
time = new Date(2026, 9, 10, 19, 30)
}
What shows, compared with the value in the class:
| In the template | Shown on the page | Value in the class |
|---|---|---|
{{ name | uppercase }} |
SPECIAL EGG PANCAKE | 'Special Egg Pancake' |
{{ price | currency:'USD' }} |
$10.00 | 10 |
{{ time | date:'dd/MM/yyyy HH:mm' }} |
10/10/2026 19:30 | a Date object |
- The
|symbol sends the value on its left to the pipe on its right. Arguments (extra settings for the pipe) come after a colon:date:'dd/MM/yyyy'. Spaces around the colon are fine:date : 'dd/MM/yyyy'works too. - The value in the class is untouched:
namestays'Special Egg Pancake', so anything else that readsnamestill gets the original text. - Each built-in pipe has a class in
@angular/common:UpperCasePipe,DatePipe,CurrencyPipe. That class is what goes inimports. In the template, the pipe is called by its short name:uppercase,date,currency. ImportingCommonModuleis the same as importing all the built-in pipes at once. new Date(2026, 9, 10)is 10 October, because JavaScript counts months from 0 (January is 0).
Built-in pipes you'll use often
| Template | Result in Angular 18 |
|---|---|
{{ name | lowercase }} |
special egg pancake |
{{ 'special egg pancake' | titlecase }} |
Special Egg Pancake |
{{ time | date }} |
Oct 10, 2026 |
{{ time | date:'dd/MM/yyyy' }} |
10/10/2026 |
{{ time | date:'HH:mm' }} |
19:30 |
{{ 0.15 | percent }} |
15% |
{{ 1250 | number }} |
1,250 |
{{ menu | json }} |
{ "name": "Pandan Pancake", "stock": 0 } |
{{ status | async }} |
the content of a Promise or Observable once it arrives, for example Shipped |
json is useful for looking inside an object while you look for a bug. async waits for data that arrives later, held in a Promise or an Observable, and shows it as soon as it arrives. async comes back in the RxJS and HTTP Client lessons.
currency, locale and dollars
A locale is the set of rules for writing numbers, dates and money in one language or country. With no settings at all, Angular uses the rules of the en-US locale (American English): commas for thousands, a dot for decimals, and two decimal digits. So {{ 10 | currency:'USD' }} shows $10.00, cents included.
The order of the currency arguments: the currency code, how to show the symbol, the number of digits, then the locale:
| Template | Result |
|---|---|
{{ price | currency:'USD' }} |
$10.00 |
{{ price | currency:'USD':'code' }} |
USD10.00 |
{{ price | currency:'USD':'symbol':'1.0-0' }} |
$10 |
{{ price | currency:'USD':'symbol':'1.0-0':'de' }} |
10 $ |
{{ 1250 | currency:'USD':'symbol':'1.0-0':'de' }} |
1.250 $ |
'1.0-0'means at least 1 digit before the decimal point, and 0 to 0 digits after it, so no decimals.'de'asks for German rules, for a page read in Germany: dots for thousands, and the symbol after the number. That data isn't installed by default, so register it once at the start of the app:
import { registerLocaleData } from '@angular/common'
import localeDe from '@angular/common/locales/de'
registerLocaleData(localeDe)
- If you forget to register that data, the pipe's text is empty. The console writes
ERROR NG0701: Missing locale data for the locale "de". - With that data,
datefollows German rules too:{{ time | date:'EEEE, d MMMM y':'':'de' }}shows Samstag, 10 Oktober 2026 (the''in the middle is the time zone, left empty). - To avoid writing
'de'in every pipe, a project can put{ provide: LOCALE_ID, useValue: 'de' }in itsproviders(the app's list of settings, covered in the Services and DI lesson). After that{{ price | currency:'USD' }}becomes 10,00 $ right away.
Chaining pipes and writing your own
Pipes can be chained: the result of the pipe on the left becomes the input of the pipe on its right. In this example, slice:0:7 takes the letters from position 0 up to, but not including, position 7:
<p>{{ name | uppercase | slice:0:7 }}</p>
<!-- SPECIAL -->
For a format you use in many places, write your own pipe:
import { Pipe, PipeTransform } from '@angular/core'
@Pipe({ name: 'price', standalone: true })
export class PricePipe implements PipeTransform {
transform(value: number): string {
return '$' + value.toLocaleString('en-US')
}
}
name: 'price'is the name written in the template after the|:{{ price | price }}(the propertypricesent to the pipeprice) shows $10, and{{ 1250 | price }}shows $1,250.transformis the method every pipe must have, andimplements PipeTransformmakes sure it's there.transformreceives the value on the left of|and returns the text that's shown. The pipe's arguments, if any, become its next parameters.toLocaleString('en-US')uses the browser's own formatting, so it needs noregisterLocaleData.- Put
PricePipein theimportsof the component that uses it. In Angular 18, a pipe withoutstandalone: trueis refused:The "PricePipe" pipe, imported from "App", is not standalone. Did you forget to add the standalone: true flag?Since Angular 19, in the exercise editor (Angular 22) too, a pipe is standalone without that line.
🤔 Pipes are pure: when they run again
Unless you set it otherwise, the pipes you write and most built-in pipes are pure (async, json, keyvalue and slice are not): Angular runs them again only when their input value is replaced. For an array, replaced means replaced with a new array. Pushing more items into the old array doesn't count. For example, the pipe totalPrice, which adds up every price in the cart with reduce:
@Pipe({ name: 'totalPrice', standalone: true })
export class TotalPricePipe implements PipeTransform {
transform(cart: number[]): number {
return cart.reduce((total, price) => total + price, 0)
}
}
// template: <p>Total: {{ cart | totalPrice | price }}</p>
Then the cart is changed in two ways:
| Action | cart |
Total shown |
|---|---|---|
| Start | [10] |
$10 |
this.cart.push(7) |
[10, 7] |
$10, the pipe doesn't run again |
this.cart = [...this.cart, 7] |
[10, 7, 7] |
$24 |
So when the data is an array or an object, replace it with a new array or object. @Pipe({ ..., pure: false }) makes a pipe run on every template check (each time Angular checks whether the display needs updating). The result is right, but wasteful.
⚠️ When a pipe causes an error or prints the wrong thing
- Forgetting to put the pipe in
imports. The whole component fails to show:NG0302: The pipe 'uppercase' could not be found in the 'App' component. Verify that it is included in the '@Component.imports' of this component. - Writing the class name in the template.
{{ name | UpperCasePipe }}is NG0302 too. The class is forimports, the short name for the template. - Cents you didn't ask for.
currency:'USD'gives $10.00. For $10, use'symbol':'1.0-0', or your ownpricepipe. - A
pushed array. A pure pipe doesn't see that change. Make a new array. - Text typed already done. The exercise checks for
| uppercasein the template and a<p>holding exactlyLEARN ANGULAR. TypingLEARN ANGULARdirectly or using.toUpperCase()doesn't pass.
TL;DR: A pipe changes how a value is shown in the template without changing the data: {{ value | pipeName:argument }}. The pipe's class (for example UpperCasePipe from @angular/common) goes in imports. The common ones: uppercase, lowercase, titlecase, date:'dd/MM/yyyy', percent, number, json, async and currency. With no other settings, currency:'USD' uses the en-US rules (locale) and shows $10.00. For $10, write currency:'USD':'symbol':'1.0-0'. For another locale such as 'de', register it with registerLocaleData(localeDe), otherwise the console writes NG0701. Pipes chain from left to right. Your own pipe is made with @Pipe({ name: 'price', standalone: true }) plus a transform method. Your own pipes are pure: Angular runs them again only when their input is replaced, so a pushed array doesn't trigger them.
⚡ | changes the display, not the data
Write:
imports: [UpperCasePipe],
template: `<h3>{{ name | uppercase }}</h3>`,
Meaning: uppercase is a built-in pipe, written after the vertical bar |. A pipe changes how a value is shown, not the value itself. If name holds 'Special Egg Pancake', the page shows SPECIAL EGG PANCAKE, but name in the class stays 'Special Egg Pancake'. The pipe's class, UpperCasePipe, goes in imports, while the template uses its short name. If UpperCasePipe is missing from imports, the whole component fails to show, with NG0302 in the console.
The exercise checks for | uppercase in the template and a <p> holding exactly LEARN ANGULAR. Typing the text directly or using .toUpperCase() doesn't pass.
⚡ currency and dollars
Write:
<p>{{ price | currency:'USD':'symbol':'1.0-0' }}</p>
Guess first: with no settings at all, what does {{ 10 | currency:'USD' }} show?
$10.00. With no settings, Angular uses the rules of the en-US locale (the format rules for American English): commas for thousands, a dot for decimals, two digits after it.
Meaning: The currency arguments (extra settings) come in order after colons: the currency code, how to show the symbol, the number of digits, then the locale. '1.0-0' asks for no decimals, so a price of 10 shows as $10. A fourth argument such as 'de' asks for German rules (10 $). Its locale data is registered once with registerLocaleData(localeDe). Forget it and the console writes NG0701.
⚡ Your own pipe
Write:
@Pipe({ name: 'price', standalone: true })
export class PricePipe implements PipeTransform {
transform(value: number): string {
return '$' + value.toLocaleString('en-US')
}
}
Meaning: This is your own pipe, named price. The transform method receives the value on the left of | and returns the text that's shown, so {{ price | price }} (the property price sent to the pipe price) shows $10. This pipe is pure: Angular runs it again only when the value on the left of | is replaced. If that value is an array, adding items with push doesn't trigger the pipe: make a new array.