1

I have an angular js directive that will take a date and format it from 2014-06-01T00:00:00 to 2014-06-01 inside of an input.

The directive loads and executes fine, the problem is, the date that I'm trying to format is part of a model that must first be retrieved from a web service. Because this is done asynchronously, the directive will execute before the data has come back from the server, which causes undefines to be sent into the directive, and the date remaining unformatted.

Is there any way to prevent this from happening, or perhaps a better way to format the date maybe?

Thank you kindly

Walter
  • 664
  • 1
  • 6
  • 19

1 Answers1

0

I think you can use a date filter:

<span >{{ yourDate | date:'yyyy-MM-dd '}}</span>

See doc: https://docs.angularjs.org/api/ng/filter/date

Mario Levrero
  • 3,345
  • 4
  • 26
  • 57