BenYsil
BenYsil

Reputation: 147

Datepicker Maxdate variable issue

I have a problem with maxDate value in ngbDatepicker :

<div class="input-group">
  <input class="form-control inputs2" formControlName="bdate" placeholder="yyyy-mm-dd" name="dp" ngbDatepicker #d="ngbDatepicker"
    [minDate]="{year: 1900, month: 1, day: 1}" [maxDate]="todaymax2">
  <div class="input-group-append">
    <button class="btn btn-outline-secondary calendar" (click)="d.toggle()" type="button"></button>
  </div>
</div>

todaymax2 value is :

public year = new Date().getFullYear();
  public month = new Date().getMonth();
  public day = new Date().getDate();
  public todaymax2 = '{year: '+ this.year +', month: '+this.month+', day: '+this.day+'}';

everything is ok i got these values :

maxDate : {year: 2019, month: 9, day: 29}
minDate : {year: 1900, month: 1, day: 1}

minDate is ok but not maxDate.

Someone have an answer ?

Thanks for help

Upvotes: 1

Views: 125

Answers (1)

Adrita Sharma
Adrita Sharma

Reputation: 22213

You have made todaymax2 a string by adding ''

Try like this:

Working Demo

public todaymax2 = {year:  this.year , month: this.month, day: this.day}

Upvotes: 1

Related Questions