简体   繁体   English

如何在日期选择器中获取特定的未来日期

[英]How to get a specific future date in date picker

I have some data comprising startdate and enddate.我有一些包含开始日期和结束日期的数据。

When I edit that data, I want to only allow future dates in enddate datepicker, but that has to be one day greater than the startdate.当我编辑该数据时,我只想在结束日期日期选择器中允许未来的日期,但这必须比开始日期大一天。

For Example: If startdate = 01/05/2020, then I want enddate to be 01/06/2020 or greater than that in datepicker.例如:如果 startdate = 01/05/2020,那么我希望 enddate 为 01/06/2020 或大于 datepicker 中的那个。

I tried that with a function naming getNextDayToStartDate() but I know I am doing something wrong.我用一个getNextDayToStartDate()的函数尝试过,但我知道我做错了什么。

Thanks.谢谢。

Please see the code here: https://stackblitz.com/edit/angular-dtnlyc请在此处查看代码: https : //stackblitz.com/edit/angular-dtnlyc

  onEditData(data): void {
    var newdate = this.getNextDayToStartDate(data.startDate);
    this.editData = {
      Name: data.Name,
      startDate: this.getDate(data.startDate),
      endDate: newdate
    }
    this.editDataDialog = true;
  }

Your function to add a day returns a value, yet you continue with the original value.添加一天的函数返回一个值,但您继续使用原始值。 Capturing the returnvalue and using that, solves the issue.捕获返回值并使用它,解决了这个问题。

Small sidenote: momentjs is a rather usefull thing for working with dates :) Might want to look in to that ;)小旁注:momentjs 是处理日期的一个相当有用的东西 :) 可能想研究一下 ;)

将 editData.startDate 添加到您的 html 中的方法调用中,这将修复它!

<input type="date" [min]="getNextDayToStartDate(editData.startDate)" [(ngModel)]="editData.endDate">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM