Reputation: 11
Im working an app with appery.io platform using ionic 1 I have a date value inside of text component.
If I use:
{{user.user_date}}
Return
{"$date":"1958-12-08T00:00:000Z"} // Correct value but wrong format
If I use:
{{user.user_date | amDateFormat:'DD/MM/YYYY'}}
Return
22/01/2021 // today date
How can I format this date value inside of component?
Thanks
Upvotes: 1
Views: 300
Reputation: 1093
Your question can be summarize as "How to use a pipe in a Typescript file". Where your can find the solution here Is it possible to use a pipe in the code?
You need to import the pipe amDateFormat
in the providers
of your module. Then, you need to inject the pipe in the constructor of the component. Finally call the transform function of the pipe.
constructor(
private datePipe: DatePipe
) {
return this.datePipe.transform(user.user_date, "DD/MM/YYYY");
}
You need to change DatePipe
with the name of the pipe you as using. The code works in the last version of Ionic/Angular, not tested in Ionic 1.
Upvotes: 1