HTML / Angular2日期选择器禁用以选择将来的日期 [英] HTML/Angular2 date picker disable to select a future date

查看:118
本文介绍了HTML / Angular2日期选择器禁用以选择将来的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与html / angular 2日期选择器有关的问题。
所以我有这样的输入标签:

I have an issue related to html/angular 2 date picker. So i have such input tag:

<input #createdAt ngModel type="datetime-local" id="createdAt" name="date" class="form-control" required>

但是我不想让用户选择将来的日期,所以只有今天和过去的日期是允许的。
如何使用angular 2实现这种行为?

but i don't want allow to a user select future date, so only today and past date is allowed. How can i achieve such behaviour with angular 2?

推荐答案

一种选择是利用<$ c < input type = datetime-local 的$ c> max 属性,例如:< input type = date name = bday max = 1979-12-31>

One of the option is to leverage the max attribute of <input type="datetime-local such as: <input type="date" name="bday" max="1979-12-31">

另一种方法是使用现有的Angular2组件,例如 Bootstrap Angular 2 中的日期选择器。该组件可高度自定义并您可以通过设置 maxDate 输入来实现目标。

An alternative is to use an existing Angular2 component, such as the date picker from Bootstrap Angular 2. The component is highly customizable and your goal can be achieved by setting the maxDate input.

这篇关于HTML / Angular2日期选择器禁用以选择将来的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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