本文介绍了如何为ng-bootstrap datepicker设置minDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我用来设置minDate的代码

Below is the code I am using to set the minDate

 <input ngbDatepicker #d="ngbDatepicker"  [minDate]="minDate" [formControl]="Form.controls['dateOfBirth']">

在组件中,我将minDate设置如下:

In the component I am setting the minDate as below:

public minDate: Date = void 0; 
constructor() {
    this.minDate = new Date(1950, 1, 1);
}

但是日期选择器仍将2007年显示为minDate.是否有任何遗漏的东西.如果需要其他任何信息,请告知我.

But the datepicker still shows 2007 as the minDate. Is there any thing that is missing. Let me know in case any other information is required.

感谢您的时间.

推荐答案

在您的代码段中,您似乎正在使用ng-bootstrap .github.io/#/components/datepicker"rel =" noreferrer> https://ng-bootstrap.github.io/#/components/datepicker .假设我是对的,您需要使用 NgbDateStruct (一个具有 year month day 等字段的对象),而不是内置的JavaScript Date 对象.例如,要将最短日期设置为今年年初,您将使用:

From your code snippet it looks like you are using ng-bootstrap from https://ng-bootstrap.github.io/#/components/datepicker. Assuming that I'm correct you need to use NgbDateStruct (an object with fields like year, month, day) instead of the built-in JavaScript Date object. For example, to set a min date to the beginning of this year you would use:

this.minDate = {year: 2017, month: 1, day: 1};

这是一个示例程序: http://plnkr.co/edit/VDEYDwp7QIZDDHatCNPh?p =预览

这篇关于如何为ng-bootstrap datepicker设置minDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 19:49