[英]How to set date and time as a default value in angularjs form field
Hi i am newbie to angularjs, I am developing registration form. 嗨,我是angularjs的新手,我正在开发注册表格。 in my form i have created_At field.
在我的表格中,我创建了At字段。 But this field should be filled automatically with current date and time in format("2015-02-26T07:28:01.596Z").
但是,此字段应使用格式(“ 2015-02-26T07:28:01.596Z”)的当前日期和时间自动填充。
i am able to get the date and time as but i am not getting how to set this value into form field. 我能够获取日期和时间,但是我没有如何在表单字段中设置此值。
am getting date as 正在约会
here i am getting value below the field, but i want to set that time and date as createdAt field value.. 在这里,我在字段下方获取值,但是我想将时间和日期设置为createdAt字段值。
here is my form code 这是我的表格代码
<body ng-app="myApp">
<div class="form-group">
<label for="user_createdAt" class="col-sm-2 control-label">{{ 'user.createdAt' | translate }}</label>
<div ng-controller="MainCtrl" class="col-sm-10">
<input type="datetime-local" id="user_createdAt" ng-model="user.createdAt" name="createdAt" class="form-control" value= "{{ date | date: 'yyyy-MM-dd' }}" />
</br>{{ date }}
<br/>{{ date | date: 'yyyy-MM-dd' }}
</div>
</div>
</body>
can anyone help me! 谁能帮我! Thanks in advance
提前致谢
Set the corresponding ngModel
to date object and Angular will populate input field properly, just remove value
attribute. 将相应的
ngModel
设置为date对象,Angular将正确填充输入字段,只需删除value
属性即可。 For example: 例如:
$scope.user.createdAt = new Date();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.