brother
brother

Reputation: 8151

Format date in Angular?

I have the following line;

body += "Date: " + myDateVar | date:'dd-MM-yyyy HH:mm' + ".";

My question is, how do i correctly format the line above, so the format actually works? I get an error, but this works fine, but just no formatting:

body += "Date: " + myDateVar + ".";

Upvotes: 2

Views: 46

Answers (1)

eliagentili
eliagentili

Reputation: 619

Supposing your code is in controller.

You need to inject in the controller the $filter service, then use it like this:

yourFilteredDate= $filter('date')(myDateVar, "dd-MM-yyyy HH:mm");

Because you can use the pipe | only in views.

Upvotes: 2

Related Questions