I am trying to bind an attribute of my model to a dateTime-local input and something is not working properly.
我试图将我的模型的属性绑定到dateTime-local输入,并且某些东西无法正常工作。
This is my model
这是我的模特
$scope.testDate = new Date($.now());
This is my html
这是我的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.
当我启动应用程序时,dateTime输入在输入框中显示“mm / dd / yyyy, - : - : - ”,但“value =”部分显示正确的dateTime值。
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?
我在这里缺少什么?
2 个解决方案
#1
8
AngularJS support the input type datetime-local
since version 1.3.0-beta.1
AngularJS支持自1.3.0-beta.1版本以来的datetime-local输入类型
And it is a breaking change that the value in model must be an Date
object instead of string like in the previous version.
并且这是一个重大变化,模型中的值必须是Date对象而不是像以前版本中的字符串。
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.
因此,如果您想使用datetime-local输入并将其与Date对象绑定,请确保使用angularjs版本1.3.0-beta.1或更新版本。
#2
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" >
#1
8
AngularJS support the input type datetime-local
since version 1.3.0-beta.1
AngularJS支持自1.3.0-beta.1版本以来的datetime-local输入类型
And it is a breaking change that the value in model must be an Date
object instead of string like in the previous version.
并且这是一个重大变化,模型中的值必须是Date对象而不是像以前版本中的字符串。
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.
因此,如果您想使用datetime-local输入并将其与Date对象绑定,请确保使用angularjs版本1.3.0-beta.1或更新版本。
#2
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" >