Learn Angular Pipes

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…

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

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 $
import { registerLocaleData } from '@angular/common'
import localeDe from '@angular/common/locales/de'

registerLocaleData(localeDe)

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')
  }
}

🤔 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

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.

What you will learn