Angular pipes take data as input and transform it to your desired output. For example, using interpolation you are displaying name of the product. Now you want the product name always displayed in the uppercase. You can do this using Angular pipe uppercase.
In above component, productName will be displayed in uppercase. Therefore, pipe takes an input and transforms it into desired output as shown below:
Angular library provides us many built-in pipes like
- DatePipe etc.
Let us see how we could use the built-in currency pipe.
You can also pass parameters to a pipe using the colon. You can pass input to currency pipe as shown below:
Even though Angular provides many default pipes, there could be requirements when you create custom pipes. Creating a custom pipe is very as simple as creating a function. Let us say that we want to create a pipe, which will capitalize first letter of each words in a string.
Consider below component,
This component will print names as below:
Now we want to capitalize the first letter of each word in the name. To do that we need to write a custom pipe. To create a pipe, you need to follow these steps: