When working with Angular you may need to do a logic that already exists in a pipe. This tutorial will show how to use pipe in services and components in Angular.

Let’s say we want to use Angular DatePipe.

Declare pipe in Module providers

To take benefit of dependency injection, you need to add the pipe to providers of your Angular module.

Use the pipe

You can use the pipe by dependency injection like below.

That’s it.