Manipulating data with pipes
Pipes allow us to filter and funnel the outcome of our expressions on a 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 in.
Before moving on to explore some of the built-in Angular pipes, we will make a change in 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\productsfolder to create a
ng generate interface product
You might be surprised...