dateTime-local does not bind properly
Asked Answered
Y

2

5

I am trying to bind an attribute of my model to a dateTime-local input and something is not working properly.

This is my model

$scope.testDate = new Date($.now());

This is my html

<input type="datetime-local" id="exampleInput" name="input" ng-model="testDate" />
value = {{testDate}}

When i start the app the dateTime input shows "mm/dd/yyyy, --:--:--" in the input box, but the "value =" part is displayed with the correct dateTime value.

If i enter a valid date in the input box it will update the value so the binding is working but something with displaying the initial value is not...

What am i missing here?

Yurev answered 11/8, 2014 at 7:52 Comment(4)
The input type="datetime-local" accept string value, not the real Date object.World
Which version of angular are you using?World
Here is the complete reference for the usage of date time. Have look at this link might help. all the best LINKTrochanter
I am using 1.2.16 since this is what i got from yeoman\bower :) Will look into changing the version and update. Thanks.Yurev
W
8

AngularJS support the input type datetime-local since version 1.3.0-beta.1

And it is a breaking change that the value in model must be an Date object instead of string like in the previous version.

Therefore, if you would like to use the datetime-local input and bind it with Date object, please ensure to use angularjs version 1.3.0-beta.1 or newer.

World answered 11/8, 2014 at 12:9 Comment(2)
Awesome! Thank you. That did the trick. Next time i will pay closer attention to the doc version :)Yurev
@Yurev Yeah, especially for angularjs, it's changing fast and introduce a lot of breaking changes along the way.World
D
0
  init the values   
 $scope.dateRange = {
    from : new Date(2010, 11, 28, 14, 57),
    to : new Date(2010, 11, 28, 14, 57)
  }   
then access 
alert($scope.dateRange.from);
alert($scope.dateRange.to);

Range From
 <input type="datetime-local" name="rangeFrom" ng-model="dateRange.from" >
 To
 <input type="datetime-local" name="rangeTo" ng-model="dateRange.to" >
Deryl answered 15/7, 2016 at 5:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.