Pipes help change how data looks in your app. Pipe chaining lets you use many pipes one after another to change data step by step.
Pipe chaining in Angular
{{ value | pipe1 | pipe2 | pipe3 }}Each pipe changes the data and passes it to the next pipe.
Use the | symbol to chain pipes in your template.
{{ birthday | date:'shortDate' | uppercase }}{{ userName | lowercase | slice:0:10 }}{{ price | currency:'USD' | lowercase }}{{ message | lowercase | titlecase }}This Angular component shows how to chain pipes in the template. It formats a date fully and then makes it uppercase. It also converts a username to lowercase and then shows only the first 5 characters.
import { Component } from '@angular/core'; @Component({ selector: 'app-pipe-chaining', template: ` <h2>Pipe Chaining Example</h2> <p>Original date: {{ birthday }}</p> <p>Formatted and uppercase date: {{ birthday | date:'fullDate' | uppercase }}</p> <p>Original text: '{{ userName }}'</p> <p>Lowercased and sliced text: '{{ userName | lowercase | slice:0:5 }}'</p> ` }) export class PipeChainingComponent { birthday = new Date(1990, 4, 15); // May 15, 1990 userName = 'AngularLearner'; }
Pipe chaining runs pipes left to right, passing the result of one pipe to the next.
Time complexity depends on each pipe used; simple pipes run fast.
Common mistake: forgetting that each pipe receives the output of the previous one, so order matters.
Use pipe chaining when you want to apply multiple simple transformations in a clear, readable way.
Pipes change how data looks in Angular templates.
Pipe chaining lets you apply many pipes one after another.
Order of pipes matters because each pipe uses the previous pipe's output.
Practice
Solution
Step 1: Understand what pipes do in Angular
Pipes transform data in templates to change how it looks.Step 2: Understand pipe chaining
Pipe chaining means applying several pipes in a row, where each pipe uses the previous pipe's output.Final Answer:
Apply multiple pipes one after another to transform data -> Option DQuick Check:
Pipe chaining = multiple pipes applied in sequence [OK]
- Confusing pipes with components or services
- Thinking pipes run in parallel instead of sequence
- Believing pipe chaining changes event bindings
Solution
Step 1: Recall Angular pipe chaining syntax
Angular uses the pipe symbol|to chain pipes in templates.Step 2: Identify correct chaining format
Multiple pipes are chained by repeating| pipeNameafter the value.Final Answer:
{{ value | pipe1 | pipe2 }} -> Option AQuick Check:
Pipe chaining uses multiple|symbols [OK]
| symbols to chain pipes [OK]- Using commas or semicolons instead of pipe symbols
- Trying to chain pipes with & or other operators
- Missing the pipe symbol between pipes
{{ 'angular' | uppercase | slice:0:3 }}What will be the displayed output?
Solution
Step 1: Apply the first pipe
The string 'angular' becomes 'ANGULAR'.uppercaseStep 2: Apply the second pipe
Slice takes characters from index 0 up to (but not including) 3, so 'ANG'.slice:0:3Final Answer:
ANG -> Option AQuick Check:
Uppercase then slice = 'ANG' [OK]
- Applying slice before uppercase
- Confusing slice end index as inclusive
- Expecting lowercase output
{{ 123 | uppercase | slice:0:2 }}Solution
Step 1: Check the first pipe
Angular'suppercaseusageuppercasepipe coerces the input to a string first (123 becomes '123'), then applies toUpperCase(), resulting in '123'.Step 2: Apply the second pipe
On '123', slice from 0 to 2 gives '12'. No error occurs.slice:0:2Final Answer:
There is no error; this works fine -> Option BQuick Check:
Uppercase coerces number to string, then slice works [OK]
- Thinking uppercase strictly requires string input without coercion
- Believing numbers cause runtime errors in pipes
- Assuming slice would fail due to input type
Solution
Step 1: Understand the desired output
The name should be fully uppercase, then only the first 5 characters shown.Step 2: Determine correct pipe order
First applyuppercaseto convert all letters, thenslice:0:5to get first 5 characters.Step 3: Check options for correct syntax and order
{{ userName | uppercase | slice:0:5 }}appliesuppercasefirst, thenslice, which matches the requirement.Final Answer:
{{ userName | uppercase | slice:0:5 }} -> Option CQuick Check:
Uppercase then slice = correct order [OK]
- Slicing before uppercase changes output
- Using commas instead of pipes
- Wrong slice parameters
Ready to prove it?
Pass the test and this pattern moves unknown
