Parameterized Pipes
Learn how Angular Pipes accept parameters to control and customize the way data is transformed and displayed.
What are Parameterized Pipes?
Parameterized Pipes are Angular Pipes that receive one or more additional values to customize their output.
Parameters are written after the pipe name using the
colon : symbol.
Parameterized Pipe Flow
Original Data
Component provides the value.
Pipe
Select the required pipe.
Parameter
Pass additional formatting information.
Output
Angular displays the customized value.
Basic Syntax
{{value | pipeName:parameter}}
{{courseFee | currency:'INR'}}
Currency Pipe with Parameter
The currency pipe accepts a currency code as
a parameter.
courseFee = 35000;
<p>
{{courseFee | currency:'INR'}}
</p>
Date Pipe with Parameter
The date pipe can receive a format parameter
to control the displayed date.
joiningDate = new Date();
<p>
{{joiningDate | date:'dd/MM/yyyy'}}
</p>
Number Pipe with Parameter
The number pipe can accept digit information
as a parameter.
marks = 87.5678;
<p>
{{marks | number:'1.2-2'}}
</p>
Percent Pipe with Parameter
The percent pipe can accept digit information
for formatting the percentage.
completion = 0.8567;
<p>
{{completion | percent:'1.1-2'}}
</p>
Multiple Parameters
Some pipes can accept more than one parameter. Parameters are separated using additional colon symbols.
{{value | pipeName:param1:param2}}
{{courseFee | currency:'INR':'symbol':'1.0-0'}}
Pipe Without Parameter
Not every pipe requires a parameter.
{{studentName | uppercase}}
Pipe with and without Parameters
| Pipe | Without Parameter | With Parameter |
|---|---|---|
| Uppercase | {{name | uppercase}} |
Not required |
| Date | {{date | date}} |
{{date | date:'dd/MM/yyyy'}} |
| Currency | {{fee | currency}} |
{{fee | currency:'INR'}} |
| Number | {{marks | number}} |
{{marks | number:'1.2-2'}} |
| Percent | {{value | percent}} |
{{value | percent:'1.1-2'}} |
Student Example
export class StudentComponent {
studentName = 'Samiksha';
courseFee = 35000;
marks = 87.5678;
completion = 0.8567;
joiningDate = new Date();
}
<h3>
{{studentName | uppercase}}
</h3>
<p>
Course Fee:
{{courseFee | currency:'INR'}}
</p>
<p>
Marks:
{{marks | number:'1.2-2'}}
</p>
<p>
Completion:
{{completion | percent:'1.1-2'}}
</p>
<p>
Joining Date:
{{joiningDate | date:'dd/MM/yyyy'}}
</p>
SAMIKSHA
Course Fee: ₹35,000.00
Marks: 87.57
Completion: 85.67%
Angular Student
Parameter Rules
Colon
Use : to pass a parameter to a pipe.
Order
Multiple parameters are passed in the required order.
Values
Parameters can be strings, numbers, or expressions.
Output
Parameters control the final formatted output.
Best Practices
- Use parameters only when customized formatting is required.
- Keep pipe expressions readable.
- Pass meaningful values to pipe parameters.
- Use the correct parameter order for multiple parameters.
- Avoid unnecessary complex expressions inside pipe parameters.
- Use built-in pipe parameters whenever they solve the formatting requirement.
Summary
- Parameterized Pipes accept additional values.
- The colon
:is used to pass parameters. - Date pipes can receive formatting parameters.
- Currency pipes can receive currency information.
- Number and percent pipes can receive digit configuration.
- Some pipes can accept multiple parameters.
- Parameters provide greater control over displayed data.