简体   繁体   中英

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.

I tried that with a function naming getNextDayToStartDate() but I know I am doing something wrong.

Thanks.

Please see the code here: 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 ;)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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