AI Hints
Home›Angular Tutorial›Pipes, Built-in Pipes and Pipe Arguments
Angular · Lesson 55 of 120

Pipes

Format values.

⏱ 2 min read▶ Video at 1:05:03🎓 Free
Watch this lesson in the Angular courseWatch on YouTube ↗Full Angular course

Data is often stored one way, but shown another. A price stored as eight point five should show as eight pounds fifty. Pipes do that formatting, right in the template.

  • Stored one way
  • Shown another
  • Pipes format it

What a pipe does

A pipe takes a value, and returns a formatted version, for display. You write it after a vertical bar, inside the curly braces. The original value doesn't change. And each pipe must be added to the component's imports.

keyvalue
value | pipeformat for display
Inside{{ ... }}
Original valueunchanged
imports: [ ]each pipe used

A first pipe

Uppercase shows the title in capital letters. Currency shows the price as British pounds. Both pipes come from at angular slash common, and are imported. The last line shows the stored values, unchanged. Run it. The title is in capitals, and the price shows as eight pounds fifty. But the values in the class didn't change.

app.tstypescript
import { Component } from '@angular/core';
import { UpperCasePipe, CurrencyPipe } from '@angular/common';

@Component({
  selector: 'app-root',
  imports: [UpperCasePipe, CurrencyPipe],
  template: `
    <h2>{{ title | uppercase }}</h2>
    <p>Price: {{ price | currency: 'GBP' }}</p>
    <p>Stored as: {{ title }}, {{ price }}</p>
  `,
})
export class App {
  title = 'the hobbit';
  price = 8.5;
}

Summary

Pipes format values for display, after a vertical bar, without changing the data. Next, the built-in pipes.

Key takeaways
  • {{ title | uppercase }}
  • {{ price | currency: 'GBP' }}
  • Data unchanged
Next up: Built-in Pipes — ready to use