Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Pipes  ›  Lesson

Common Built-in Pipes

Common Pipes 12 minA pipe takes a value in a template and returns a display-ready version of it, and Angular ships ready-made pipes for dates, numbers, currency, percentages, text case and debugging.

Common Built-in Pipes

The plant card is technically correct and hard to read: "Tue Mar 03 2026 09:14:00 GMT+0530", "349.5", "0.62". The data is right; its presentation is wrong. You could write formatting methods for each, but Angular already ships them as pipes.

The rule

A pipe changes how a value looks, never what it is.

A pipe sits after a | in a template expression and turns the value on its left into display text:

<h3>{{ plant().name | titlecase }}</h3>
<p>Last watered {{ plant().lastWatered | date:'d MMM' }}</p>
<p>Price {{ plant().price | currency:'INR' }}</p>
<p>Humidity {{ plant().humidity | percent }}</p>

With a name of 'boston fern', a price of 349.5 and humidity 0.62, this shows "Boston Fern", "Last watered 3 Mar", "Price ₹349.50" and "Humidity 62%" (for an English locale). The signal still holds the original values; only the screen changes.

The everyday set, all from @angular/common:

Pipe Class Example output
date DatePipe Mar 3, 2026, or any format you pass
currency CurrencyPipe ₹349.50 with currency:'INR'
number DecimalPipe 3.14 with number:'1.0-2'
percent PercentPipe 62% from 0.62
uppercase, lowercase, titlecase UpperCasePipe etc. Changes letter case
json JsonPipe The object as JSON text, handy for debugging
slice SlicePipe Part of a string or array
async AsyncPipe The latest value of a promise or observable

Arguments follow a colon: date:'d MMM', number:'1.0-2' (at least 1 whole digit, 0 to 2 decimals).

Because pipes are template dependencies, a standalone component must import each class it uses:

imports: [DatePipe, CurrencyPipe, PercentPipe, TitleCasePipe],

Notice that the number pipe's class is DecimalPipe, a common stumble.

The shortcut

When raw data looks ugly on screen, name its type first: date, money, ratio, count, text. Each type has one natural pipe. Then pick the argument that matches how a person would say it aloud.

Formatting the watering reminderStep 1 of 4
  1. Name the type

    nextWatering is a Date.

The trap is formatting values in the class and storing the formatted strings. Then you cannot sort by date or add up prices any more. Keep raw data in signals and format at the last moment, in the template.

Drills

Answer fast — trust the rule.

quick drill

What does {{ 0.62 | percent }} display?

quick drill

Which class must be imported to use the number pipe?

quick drill

After {{ plant().name | uppercase }}, what does plant().name hold?

quick drill

How do you pass the format 'd MMM' to the date pipe?

Remember

  • Pipes format values for display; the underlying data stays the same.
  • Name the value's type, pick its pipe, pass arguments after :, and import the pipe class.
  • Trap: storing pre-formatted strings; format in the template instead.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainDress up the plant card

The Greenhouse plant card shows raw data: a Date object for lastWatered, a price of 349.5 rupees, a humidity of 0.62, and the name 'boston fern'. Write the template using built-in pipes so these read naturally, list what the component must import, and explain whether the pipes change the stored data.