I'm coding in .NET MVC and would like to pass a stored DateTime object to the front-end as an initial value for a Date object in a controller.
Here's what I've tried:
ng-init="params.datetime = new Date()"
This doesn't seem to work, and I'm getting a syntax error.
How can I pass in a Date object as an initial property for a scope variable?
UPDATE
I forgot to include the Razor code in my code sample.
ng-init="params.datetime = new Date('@Model.DepartureTime.ToString("s")')"
Angular scope doesn't know about
Date
Try to use:
and after:
Demo 1 Fiddle
As an answer for your EDIT,
rewrite
Date
as method:and:
Demo 2 Fiddle
Another way to do it, in my case I've added a now function in my $rootScope in a config block:
and then can be used like this:
or just
but I prefer using $root so we know exactly where the
now
function is located