CHAPTER 08
Beginner
Pipes in Angular
Updated: May 18, 2026
5 min read
# CHAPTER 8
Pipes in Angular
1. Chapter Introduction
A Pipe transforms data directly inside an Angular template without needing to modify the original data or write transformation functions in the component class. Need to format1234567 as $1,234,567.00? Or display 2024-01-15 as January 15, 2024? Angular Pipes do this in a single character — the pipe symbol |.
2. Learning Objectives
-
Use built-in pipes:
uppercase,lowercase,date,currency,number,json.
- Chain multiple pipes together.
-
Create a custom pipe using
ng generate pipe.
3. Built-in Pipes
typescript
html
4. Chaining Pipes
You can chain pipes using multiple| symbols. They process left to right.
html
5. Custom Pipes
Let's build ashorten pipe that truncates text to a given length.
bash
shorten.pipe.ts
html
6. Pure vs Impure Pipes
- Pure Pipe (Default): Only recalculates when the input reference changes. Very performant.
- Impure Pipe: Recalculates on every change detection cycle. Use only when absolutely necessary as it is expensive.
typescript
7. Common Mistakes
- Modifying data in the template: Pipes should only format data for display, not modify the actual source array or variable.
- Using impure pipes on large datasets: An impure pipe runs on every change detection cycle, which can cause severe performance issues in lists with hundreds of items.
8. MCQs with Answers
Q1. What symbol is used to apply a pipe in an Angular template? a) @ b) # c) | Answer: c) |.
Question 2
Which pipe transforms text to uppercase?
Question 3
Which pipe formats a number as a currency?
Question 4
How do you create a custom pipe?
Question 5
What interface must a custom pipe class implement?
Question 6
Which pipe is used to display JavaScript objects for debugging?
Question 8
Which pipe automatically subscribes to an Observable and displays its value?
Question 9
What is the key difference between a pure and impure pipe?
Question 10
What is the date pipe format string for "January 15, 2024"?
9. Interview Questions
- Q: What is the difference between a pure and impure pipe? Give a use case for each.
- Q: How would you build a custom pipe to filter a list of products by category?
10. Summary
Pipes are Angular's elegant solution for transforming display values without polluting component logic. They are reusable, chainable, and composable. Theasync pipe is particularly powerful as it automatically handles Observable subscriptions and unsubscriptions, preventing memory leaks.