← Back to Chapters

Built-in Pipes

? Built-in Pipes

? Quick Overview

Angular provides several built-in pipes to transform data directly in the template. You can format dates, currencies, numbers, and change text case without touching the component logic, making your templates cleaner and easier to read.

A pipe takes an input value, transforms it, and returns the formatted result: value | pipeName:arg1:arg2

? Key Concepts

  • Pipes are simple functions used in Angular templates to transform data.
  • Syntax: {{ value | pipeName:arg1:arg2 }}
  • You can chain multiple pipes, for example: {{ dateValue | date:'short' | uppercase }}.
  • Built-in pipes handle common tasks like date, currency, uppercase, lowercase, json, and slice.
  • Pipes only affect how data is displayed; they do not change the original value in the component.

? Syntax & Usage

Basic syntax inside a template interpolation:

{{ value | pipeName:arg1:arg2 }}

  • date: formats Date objects into human-readable strings.
  • currency: formats a number as localized currency.
  • uppercase / lowercase: convert text to upper or lower case.
  • json: pretty-prints an object as JSON.
  • slice: returns a sub-string or sub-array from the original value.

? Code Example – Common Built-in Pipes

? View Code Example (Template)
<!-- app.component.html: Display values using built-in pipes -->
<p>Current Date: {{ today | date:'fullDate' }}</p>
<p>Price: {{ amount | currency:'USD' }}</p>
<p>Uppercase: {{ name | uppercase }}</p>
<p>Lowercase: {{ name | lowercase }}</p>
<p>JSON: {{ user | json }}</p>
<p>Slice: {{ message | slice:0:5 }}</p>
? View Code Example (Component)
// app.component.ts: Define values used by the template
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {
  today = new Date();            // current date
  amount = 2499.99;              // product price
  name = 'angular pipes';        // sample text
  message = 'Hello Pipes!';      // message to slice
  user = {                       // user object for json pipe
    id: 1,
    name: 'John Doe',
    role: 'Admin'
  };
}

? Live Output / Explanation

? What this will display

  • Date pipe – Renders something like: Wednesday, December 10, 2025 for fullDate.
  • Currency pipe – Renders: $2,499.99 when using currency:'USD'.
  • Uppercase / Lowercase – Convert "angular pipes" to "ANGULAR PIPES" and "angular pipes" respectively.
  • JSON pipe – Shows a formatted JSON string for the user object.
  • Slice pipemessage | slice:0:5 returns "Hello" from "Hello Pipes!".

? Tips & Best Practices

  • Use pipes directly in templates to keep your component logic clean and focused on data, not formatting.
  • Chain multiple pipes for more complex transformations, such as {{ today | date:'short' | uppercase }}.
  • Use date and currency pipes for localized formats based on the current locale.
  • Remember that pipes do not mutate your original data; they only change how it appears in the template.
  • Prefer built-in pipes whenever possible instead of writing custom formatting logic in components.

? Try It Yourself / Practice

  • Display the current date in short, medium, and fullDate formats using the date pipe.
  • Create a list of product prices and format each one with a different currency using the currency pipe.
  • Take a user-entered string and show it in both uppercase and lowercase using the respective pipes.
  • Use the slice pipe to display only the first 3 items of an array and the first 5 characters of a string.
  • Create a complex object (e.g., a user profile) and render it using the json pipe to see its structure.