代码之家  ›  专栏  ›  技术社区  ›  Channa

如何禁用角度p日历中的未来日期?

  •  11
  • Channa  · 技术社区  · 8 年前

    我使用日历输入,如下所示。

    <p-calendar  maxDate="dateTime" showTime="true" hourFormat="12" showButtonBar="true" [(ngModel)]="dateTime" name="timeOfUse" required #timeOfUse="ngModel">
              </p-calendar>
    

    我想在此日期选择器中禁用未来日期。这可能是一个简单的属性,但我无法理解。感谢您的帮助

    2 回复  |  直到 8 年前
        1
  •  12
  •   Antikhippe    8 年前

    你还不远!只需将方括号添加到 maxDate 它将发挥作用:

    <p-calendar  [maxDate]="dateTime" showTime="true" hourFormat="12" showButtonBar="true" [(ngModel)]="dateTime" name="timeOfUse" required #timeOfUse="ngModel">
    </p-calendar>
    

    例如,如果您想禁用今天后3天的日期:

    export class AppComponent {
    
       dateTime = new Date();
    
       constructor() {
         this.dateTime.setDate(this.dateTime.getDate() + 3);    
       }
    
    
    }
    
        2
  •  2
  •   Nisal Edu    8 年前

    在网上找到这个可能会帮助你阅读主题 禁用特定日期和/或天数

    日期限制

    [maxDate]="maxDateValue" 
    

    https://www.primefaces.org/primeng/#/calendar

    参考

    https://forum.primefaces.org/viewtopic.php?f=35&t=49578