Return to site

ANGULAR INTERVIEW QUESTION: What are pipes?

September 22, 2021

A pipe is a native Angular element, which takes data in input and transforms it to a specified kind of output.

It is mainly for simple display arrangements.

ð“ðĄðžðŦ𝐞 𝐚ðŦ𝐞 𝐭𝐰ðĻ ðĪðĒ𝐧𝐝𝐎 ðĻ𝐟 ðĐðĒðĐ𝐞𝐎:

―𝐍𝐚𝐭ðĒðŊ𝐞 ðĐðĒðĐ𝐞𝐎 which are directly available in your templates:

Your birthday is the {{ birthday | date }}

Here, in the example above, we use the pipes to transform a date in a pretty format, easy to read for the user.

The available pipes in Angular are: DatePipe, UpperCasePipe, LowerCasePipe, CurrencyPipe & PercentPipe.

―𝐂ðŪ𝐎𝐭ðĻðĶ ðĐðĒðĐ𝐞𝐎 that cover cases not covered by Angular:

𝐘ðĻðŪ 𝐜𝐚𝐧 𝐜ðĻðĶ𝐛ðĒ𝐧𝐞 ðĐðĒðĐ𝐞𝐎:

 {{ birthday | date | uppercase }}

𝐈𝐧 𝐜ðĻ𝐧𝐜ðĨðŪ𝐎ðĒðĻ𝐧, Pipes allows doing low complexity data transformations inside templates.

For more complex transformation, you would rather use services or dedicated components.