Reputation: 325
I have an object with a date property vm.SomeDate
in the following format:
2012-10-12T00:00:00
In my Angular app, I then have an input field with type="date"
<input type="date" ng-model="vm.SomeDate">
This doesn't work out of the box though, it just shows me a datepicker with an empty date, dd.mm.yyyy
. I have tried various filters such a vm.SomeDate | date:'YYYY.MM.yyyy
, but they don't seem to help at all.
How can I get the datepicker working with this date format?
Upvotes: 1
Views: 106
Reputation: 3437
$( ".selector" ).datepicker({
dateFormat: "yy-mm-ddT00:00:00"
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<input class='selector' >
Upvotes: 1
Reputation: 152294
Just pass a Date
object as a model to the <input>
. If vm.SomeDate
is a string, you can use it as a constructor argument:
new Date($scope.vm.SomeDate);
Upvotes: 1