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
{{ value | pipeName:arg1:arg2 }}{{ dateValue | date:'short' | uppercase }}.date, currency, uppercase, lowercase, json, and slice.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.
<!-- 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>
// 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'
};
}
fullDate.currency:'USD'."angular pipes" to "ANGULAR PIPES" and "angular pipes" respectively.user object.message | slice:0:5 returns "Hello" from "Hello Pipes!".{{ today | date:'short' | uppercase }}.date and currency pipes for localized formats based on the current locale.short, medium, and fullDate formats using the date pipe.currency pipe.uppercase and lowercase using the respective pipes.slice pipe to display only the first 3 items of an array and the first 5 characters of a string.json pipe to see its structure.