Igor Simic
3 years 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')