user860067 user860067 - 1 year ago 135
AngularJS Question

dateTime-local does not bind properly

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download