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

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

问题描述

我已经在我的angular2应用程序中尝试了很多日期选择器,但没有一个是工作的。虽然日期选择器在视图上显示,但是所选日期的值不在ngModel变量中。

解决方案

事实上,您可以通过在<$ c中添加日期值来使用datepicker $ c> type 您输入的属性:

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

在Chrome和Microsoft Edge(不在Firefox中)的某些浏览器中,您可以点击输入显示日期选择器。只有当鼠标悬停在输入端时,图标才会出现。



要使浏览器有东西,您应该考虑使用符合Angular2的库,如:




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.

解决方案

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"/>

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.

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

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

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