如何在 Angular 2 中使用日期选择器? [英] How to use date picker in Angular 2?

查看:30
本文介绍了如何在 Angular 2 中使用日期选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 angular2 应用程序中尝试了许多日期选择器,但它们都不起作用.虽然日期选择器显示在视图上,但所选日期的值没有进入 ngModel 变量.

I have tried many date picker in my angular2 app but none of them is working.Although the date picker is displaying on the view but the value of selected date is not getting in the ngModel variable.

推荐答案

实际上,您可以通过简单地将 date 值添加到 type 属性中来使用日期选择器您的输入:

In fact, you can use a datepicker by simply adding the date value into the type attribute of your inputs:

<input type="date" [(ngModel)]="company.birthdate"/>

在某些浏览器中,例如 Chrome 和 Microsoft Edge(不是在 Firefox 中),您可以单击输入中的图标以显示日期选择器.仅当您将鼠标悬停在输入上时才会出现图标.

In some browsers like Chrome and Microsoft Edge (not in Firefox), you can click on the icon within the input to display the date picker. Icons appear only when you mouse is over the input.

要拥有跨浏览器的功能,您应该考虑使用 Angular2 兼容库,例如:

To have something cross browsers, you should consider to use Angular2 compliant libraries like:

这篇关于如何在 Angular 2 中使用日期选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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