HTML5日期输入字段与angularJS设置默认值 [英] Set default value of HTML5 date input field with angularJS

查看:1328
本文介绍了HTML5日期输入字段与angularJS设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能结合我在瞬间产生的日期和时间输入字段的默认值。我试着NG-模型,并将其直接绑定到value属性。但没有它似乎工作。有没有一种方法,使工作?

I am hoping to bind the default value I generated in moment to the date and time input field. I tried ng-model and directly binding it to the value attributes. But none of it seems to work. Is there a way to make it work?

编辑:同时,如何将时间输入字段绑定以及

Also, how to bind the time input field as well?

<body ng-app="myApp">
<div ng-controller="MyCtrl">
    <input type="date" ng-model="date" value="{{date}}">
        <p>{{date}}</p>
    <input type="time" ng-model="time" value="{{time}}">    
</div>

下面是它的一个小提琴: http://jsfiddle.net/chrisyeung/bF9Pq/

Here is a fiddle for it: http://jsfiddle.net/chrisyeung/bF9Pq/

推荐答案

如果您使用Chrome,你必须指定日期格式为'YYYY-MM-DD'。

If you're using chrome you have to specify the Date format as 'yyyy-MM-dd'.

$scope.date = $filter("date")(Date.now(), 'yyyy-MM-dd');

这根本不​​会以其他方式使用。这里有一个工作版本的 http://jsfiddle.net/bF9Pq/4/

这篇关于HTML5日期输入字段与angularJS设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆