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?

user860067
  • 121
  • 1
  • 4

2 Answers2

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.

runTarm
  • 11,537
  • 1
  • 37
  • 37
  • Awesome! Thank you. That did the trick. Next time i will pay closer attention to the doc version :) – user860067 Aug 11 '14 at 12:59
  • @user860067 Yeah, especially for angularjs, it's changing fast and introduce a lot of breaking changes along the way. – runTarm Aug 11 '14 at 13:02
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" >
Vinayak Shedgeri
  • 2,222
  • 1
  • 21
  • 24