Angular 2 datepicker组件,可禁用特定日期 [英] Angular 2 datepicker component that enables to disable specific dates

查看:197
本文介绍了Angular 2 datepicker组件,可禁用特定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个角度为2的日期选择器组件,使我可以禁用特定日期的数组?

is there an angular 2 datepicker component that enables me to disable an array of specific dates?

我知道为jquery datepicker创建自定义包装是一种选择.

I know that creating a custom wrapper for jquery datepicker is an option.

我找到了这3个日期选择器,但似乎没人能够禁用某些日期.

I found these 3 datepickers, but no one seem to capable of disabling certain dates.

https://github.com/kekeh/mydatepicker

https://github.com/jkuri/ng2-datepicker

www.primefaces.org/primeng/#/calendar

www.primefaces.org/primeng/#/calendar

我将在http请求中获取列表.另外,我需要禁用当前日期之前的所有日期.

I will be getting the list in an http request. In addition, I need to disable all dates before the current date.

这是预订用例.我需要禁用今天之前的所有日期,并且需要禁用将在http请求中获得的数组中的所有日期.

It is a reservation use case. I need to disable all dates before today and I need to disable all dates from an array I will get in an http request.

使用验证器不是一个好选择,因为用户需要查看他无法选择的内容.

The usage of validator is not a good option, because the user needs to see what he cannot choose.

我刚刚找到了这一个 https://github. com/valor-software/ng2-bootstrap/tree/master/components/datepicker ,我将继续使用它,然后发布答案.

I have just found this one https://github.com/valor-software/ng2-bootstrap/tree/master/components/datepicker, I will go with this one and later post an answer.

推荐答案

这个有它. http://www.primefaces.org/primeng/#/calendar

请参阅日期限制"部分

<p-calendar [(ngModel)]="dateValue" minDate="-1m" maxDate="+1m" [readonlyInput]="true">></p-calendar>

+它使用jquery UI datepicker,因此您可以使用其中的一些: jQuery UI datepicker.禁用日期数组

+it uses jquery UI datepicker so you can use some of this: Jquery UI datepicker. Disable array of Dates

但是...

最佳方法可能只是为此做一个验证器,并阻止用户选择该值.您是与该解决方案无关的第三方.这对angular2动态世界很有帮助.

Best way of doing this is probably just make an validator for this, and prevent user of selecting the value. You are 3rd party independent with this solution. Which can be pretty helpful in angular2 dynamic world.

问题编辑后

我将在http请求中获取列表.另外,我需要 禁用当前日期之前的所有日期.

I will be getting the list in an http request. In addition, I need to disable all dates before the current date.

如果您不想用角度编码(验证器或某些更改检测). primeNG限制将使您能够禁用日期范围. (最大/最小日期)

If you don't want to code it in angular (validator or some change detection). The primeNG restrict will give you ability to disable a range of dates. (max/min date)

这篇关于Angular 2 datepicker组件,可禁用特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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