Datepicker Maxdate变量问题

Datepicker Maxdate variable issue

我对 ngbDatepicker 中的 maxDate 值有疑问:

<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 值为:

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+'}';

一切正常,我得到了这些值:

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

minDate 可以,但 maxDate 不行。

有人有答案吗?

感谢帮助

您通过添加 ''

使 todaymax2 成为一个字符串

这样试试:

Working Demo

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