Manipulating data with pipes
Pipes allow us to transform the outcome of our expressions at the view level. They take data as input, transform it into the desired format, and display the output in the template.
The syntax of a pipe is pretty simple, consisting of the pipe name following the expression we want to transform, separated by a pipe symbol (|
). Pipes are usually used with interpolation in Angular templates and can be chained to each other. Angular has a wide range of pipe types already baked into it.
Before moving on to explore some of the built-in Angular pipes, we will make a change to our Angular working application to demonstrate their use better. The products
array in the product list component is currently an array of string values. We will convert it into an array of product objects using interfaces:
- Run the following Angular CLI command inside the
src\app\products
folder to create aproduct
interface:ng generate interface product...