In this article we will learn about How to pass parameters to pipes in Templates. We can pass parameters to the pipe. we have to use a specific format to pass parameters with using colon. Please read my previous article about How to use pipes in Component Class.
Let’s look at the below example pipe Decimal-Pipe where we are using the colon :
to pass locale and specific way to display numbers. we can pass multiple parameters as well.
- On the below we create a decimal value in typescript.
- On the HTML markup we formatted to passing parameters to pipes in Templates.
export class AppComponent {
myNumber : number = 2896.597;
}
<div class="form-group">
<label for="usr">Decimal Pipe Test:</label>
<input type="number" [(ngModel)]="myNumber" class="form-control col-sm-6" id="usr">
</div>
<div class="mrg10">
<h5>Result with no format:</h5>
<p>{{myNumber | number}}</p>
</div>
<div class="mrg10">
<h5>Result with format (2.1-6):</h5>
<p>{{myNumber | number:'2.1-6'}}</p>
</div>
<div class="mrg10">
<h5>Result with format (1.0-0):</h5>
<p>{{myNumber | number:'1.0-0'}}</p>
</div>
<div class="mrg10">
<h5>Result with format (3.1-5) and locale en:</h5>
<p>{{myNumber | number:'3.1-5':'en'}}</p>
</div>

Conclusion
In this article we will learnt aboutĀ How to pass parameters to pipes in Templates. We can pass parameters to the pipe. we have to use a specific format to pass parameters with using colon.
Leave behind your valuable queries and suggestions in the comment section below. Also, if you think this article helps you, do not forget to share this with your developer community. Happy Coding š
Related Articles
- Introduction to GraphQL
- Creating a Sample ReactJs Application using VS Code
- How to use Policy-based Authorization using JWT in .Net Core 7 and Angular
- BuildingĀ Single Page Applications(SPA) with ReactJS
- How to deploy Angular App in Azure Static Web App
- How to create a react App
- React Installation and Environment Setup
- Intro to ReactJS Application
- Global Error Handling in Angular
- How to host Angular app on AWS S3 bucket using CloudFront
Jayant Tripathy
Coder, Blogger, YouTuberA passionate developer keep focus on learning and working on new technology.