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

Pipe Arguments

Fine tuning.

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

Most pipes can be fine tuned. Which currency, which date format, how many decimals. We pass that with arguments.

  • Fine tuning
  • Currency, date format
  • Arguments

Arguments and chaining

A colon after the pipe name passes an argument. More colons pass more arguments. And several pipes can be chained, one after another. Each one formats the result of the one before it.

keyvalue
currency: 'USD'one argument
slice: 0 : 12two arguments
date: 'd MMMM yyyy'a format
a | slice | uppercasechained

Fine tuned pipes

Currency takes the currency code, dollars, or euros. Date takes a format pattern. Number one dot one dash one means exactly one decimal place. And slice cuts the title, before uppercase changes it. Run it. Each value follows its arguments. And the chained pipes gave a short, capitalised title.

app.tstypescript
import { Component } from '@angular/core';
import { CurrencyPipe, DatePipe, DecimalPipe } from '@angular/common';
import { SlicePipe, UpperCasePipe } from '@angular/common';
@Component({
  selector: 'app-root',
  imports: [CurrencyPipe, DatePipe, DecimalPipe, SlicePipe, UpperCasePipe],
  template: `
    <p>{{ price | currency: 'USD' }} or {{ price | currency: 'EUR' }}</p>
    <p>{{ published | date: 'd MMMM yyyy' }}</p>
    <p>Rating: {{ rating | number: '1.1-1' }}</p>
    <p>{{ title | slice: 0 : 12 | uppercase }}...</p>
  `,
})
export class App {
  price = 11.99;
  published = new Date('1954-07-29');
  rating = 4.6666;
  title = 'The Fellowship of the Ring';
}

Summary

Colons pass arguments to pipes, and several pipes can be chained. Next, writing your own pipes.

Key takeaways
  • currency: 'USD'
  • date: 'd MMMM yyyy'
  • slice | uppercase
Next up: Custom Pipes — your own formatting