如何在输入日期加载带有angular的值? [英] How can I load value on input date with angular?

查看:85
本文介绍了如何在输入日期加载带有angular的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular 1.5.5进行编程,并且正在使用Materialize CSS 0.97.6. 我有这个问题.

I'm programming with Angular 1.5.5 and I'm using Materialize CSS 0.97.6. I have this problem.

在控制器上,我有$scope.myDate = '2017-01-13T02:06:40' 在HTML文件中,我有<input type='date' class='form-control datepicker' value="{{(myDate | date: 'dd/MM/yyyy')}}">

On controller, I have $scope.myDate = '2017-01-13T02:06:40' In the HTML file, I have <input type='date' class='form-control datepicker' value="{{(myDate | date: 'dd/MM/yyyy')}}">

但是输入字段未显示任何内容.

But the input field doesn't show anything.

如果我放<input type='date' class='form-control datepicker' value="13/01/2017">,它会起作用.

If I put <input type='date' class='form-control datepicker' value="13/01/2017"> it works.

我这样做是为了检查myDate变量<div ng-bind="myDate | date : 'dd/MM/yyyy'"></div>,它也起作用.

I did it to check the myDate variable <div ng-bind="myDate | date : 'dd/MM/yyyy'"></div> and it works too.

所以,任何人都可以解释为什么在使用变量时为什么没有将值加载到输入中?

So, anyone can explain why the value is not being loaded to input when I use the variable?

推荐答案

无法更改html5输入日期类型的格式,有关更多信息,请参见下面的先前答案:

There is no way possible to change the format of html5 input date type, for more info see the previous answer below:

是否有任何方法可以更改输入类型= 日期"格式?

因此,如果该格式是强制性格式,则可以在有角 ui.bootstrap 库,您可以在其中直接设置格式,这是它们的 plunker示例:

So if the format is mandatory you can use the Datepicker Popup element in angular ui.bootstrap library for example where you can set the format directly, this is their plunker example :

否则,如果格式不是您必需的,则只需实例化一个新的date对象,它将像这样工作:

otherwise if the format is not mandatory to you, just instantiate a new date object and it will work like this:

$scope.myDate = new Date('2017-01-13T02:06:40');
<input type="date" class="form-control datepicker" ng-model="myDate">

或者如果您不关心编辑日期而只想显示日期,则只需将输入的类型更改为文本,它也将像这样工作:

or if you don't care about editing the date and you want to only show it you can just change the type of the input to text and it will also work like this:

$scope.myDate = '2017-01-13T02:06:40';
<input type="text" class="form-control datepicker" ng-readonly="true" style="background: #ffffff;" value="{{myDate | date: 'dd/MM/yyyy'}}">

这篇关于如何在输入日期加载带有angular的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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