简体   繁体   English

在 Angular 的 Formly Datepicker 中禁用未来日期

[英]Disable future dates in Formly Datepicker in Angular

I am using Formly with Material in Angular and have a datepicker.我在 Angular 中使用 Formly 和 Material 并有一个日期选择器。 All I want to do is disable future dates so they cannot be selected when selecting a date, I can't seem to find anything online!我想要做的就是禁用未来的日期,以便在选择日期时无法选择它们,我似乎在网上找不到任何东西!

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?
      },
    },
  ];
}

You can play around with the code here: https://stackblitz.com/angular/gkyxqxygybo?file=src%2Fapp%2Fapp.component.ts您可以在此处使用代码: https : //stackblitz.com/angular/gkyxqxygybo?file=src%2Fapp%2Fapp.component.ts

OK I finally found the answer here .好的,我终于在这里找到了答案。 I needed to add我需要添加

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

to the template options.到模板选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM