DateTime-local does not bind properly

I am trying to bind an attribute of my model to the local input of dateTime 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 launch the application, the dateTime input shows "mm / dd / yyyy, -: -: -" in the input field, but the "value =" part is displayed with the correct DateTime value.

If I enter the correct date in the input field, it will update the value so that the binding works, but something with displaying the initial value does not ...

What am I missing here?

+5
source share
2 answers

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

And this is an interrupt change that the value in the model should be a Date object instead of a string, as in the previous version.

Therefore, if you want to use the datetime-local input and bind it to a Date object, make sure you are using angularjs version 1.3.0-beta.1 or later.

+8
source
  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" > 
0
source

Source: https://habr.com/ru/post/1200007/


All Articles