Igor Simic
10 months ago

Angular pipe in component or service


How to use angular pipe data formatter in component or service? Here is short example how you can easily achieve this:

Just make new instance of DatePipe class and use the method transform:
const formatDate = new DatePipe('en').transform(myDate, 'dd-MM-yyyy');

Another way would be to use predefined angular method:
formatDate(data.created_at, 'shortDate', 'en')