【问题标题】:Disable future dates in Formly Datepicker in Angular在 Angular 的 Formly Datepicker 中禁用未来日期
【发布时间】:2020-02-12 23:05:49
【问题描述】:

我在 Angular 中使用 Formly 和 Material 并且有一个日期选择器。我想要做的就是禁用未来的日期,因此在选择日期时无法选择它们,我似乎无法在网上找到任何东西!

export class AppComponent {
  form = new FormGroup({});
  model: any = {};
  options: FormlyFormOptions = {};
  fields: FormlyFieldConfig[] = [
    {
      key: 'Datepicker',
      type: 'datepicker',
      templateOptions: {
        label: 'Datepicker',
        placeholder: 'Placeholder',
        description: 'Description',
        required: true,
        //what to put here to disable future dates?
      },
    },
  ];
}

您可以在此处使用代码: https://stackblitz.com/angular/gkyxqxygybo?file=src%2Fapp%2Fapp.component.ts

【问题讨论】:

  • 我发现 here 可以使用 maxDate 但是当我在上面声明表单的地方添加 date = new Date(); 然后 maxDate: this.date 时,它​​什么也没做跨度>

标签: angular datepicker angular-material angular-formly


【解决方案1】:

好的,我终于找到了答案here。我需要添加

datepickerOptions: {
  max: new Date(),
},

到模板选项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多