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?
Input type "datetime-local" is not supported in Firefox hence it shows a text box, in this case, you can use input type as "date". As "datetime-local" shows the time as well and if you have the same requirement, you can use Input type "time" also to show the time. I hope this helps.
Browser Support Note: The <input type="datetime-local"> element does not show any datetime field/calendar in Firefox.
Definition and Usage. The <input type="datetime-local"> defines a date picker. The resulting value includes the year, month, day, and time.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With