Introduction
Pipes help change how data looks in your app without changing the data itself. They make it easy to show data in a way people understand.
Pipes help change how data looks in your app without changing the data itself. They make it easy to show data in a way people understand.
{{ value | pipeName[:parameter] }}{{ birthday | date:'longDate' }}{{ price | currency:'USD' }}{{ name | uppercase }}{{ description | slice:0:20 }}This component shows how pipes change data display without changing the data itself. You see the original and the transformed versions side by side.
import { Component } from '@angular/core'; @Component({ selector: 'app-pipe-demo', template: ` <h2>Pipe Examples</h2> <p>Original date: {{ birthday }}</p> <p>Formatted date: {{ birthday | date:'longDate' }}</p> <p>Price: {{ price | currency:'USD' }}</p> <p>Name uppercase: {{ name | uppercase }}</p> <p>Short description: {{ description | slice:0:15 }}...</p> ` }) export class PipeDemoComponent { birthday = new Date(1990, 0, 1); price = 1234.5; name = 'angular learner'; description = 'This is a long description that needs to be shortened.'; }
Pipes do not change the original data, only how it looks.
You can chain multiple pipes like {{ value | pipe1 | pipe2 }}.
Angular has many built-in pipes, and you can create your own.
Pipes make data easier to read and understand.
They help format dates, numbers, text, and more.
Using pipes keeps your templates clean and simple.
| symbol followed by the pipe name and optional parameters inside single quotes.{{ today | date:'shortDate' }} correctly uses {{ today | date:'shortDate' }}. Others misuse colon or function call syntax.{{ 1234.5678 | number:'1.2-2' }}{{ user.birthdate | date:shortDate }}shortDate should be 'shortDate'.{{ user.fullName | uppercase }} - {{ user.registrationDate | date:'shortDate' }} correctly applies uppercase to the name and date to the date separately. {{ user.fullName | uppercase | date:'shortDate' }} chains incompatible pipes on one value. {{ user.fullName + ' - ' + user.registrationDate | uppercase | date:'shortDate' }} misuses concatenation with pipes. {{ (user.fullName | uppercase) + ' - ' + (user.registrationDate | date:shortDate) }} omits quotes around the pipe parameter shortDate.Pass the test and this pattern moves unknown