【问题标题】:Max date for mat-calendar垫日历的最大日期
【发布时间】:2020-05-12 21:25:48
【问题描述】:

我很早就在使用<mat-calendar>。我现在尝试设置maxDate(即)禁用所有以前的日期。但现在我发现现在支持 .

代码

   <mat-calendar name="appointment_date" [maxDate]="maxDate"  [selected]="selectDate" (selectedChange)="onSelect($event)">
            </mat-calendar>

maxDate = new Date();

我也尝试了[max],但没有成功。请帮帮我

【问题讨论】:

    标签: angular angular-material


    【解决方案1】:

    您需要检查maxDate 变量值和格式。

    我试图重现 [maxDate] 属性,它起作用了。

    https://stackblitz.com/edit/angular-mat-calendar-ggs5ha

    【讨论】:

      【解决方案2】:

      这适用于禁用以前的日期:

      在你的 html 中试试这个:

      <mat-calendar name="appointment_date" [min]="minDate" [selected]="selectDate" 
                    (selectedChange)="onSelect($event)">
      </mat-calendar>
      

      这在你的 component.ts 中:

        minDate = new Date();
      

      【讨论】:

        猜你喜欢
        • 2010-12-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-19
        • 1970-01-01
        • 2019-05-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多