首页 文章

如何在ng2-date-picker中设置选项?

提问于
浏览
1

目前我正在使用角度2日期选择器ng2-date-picker . 这里我不知道如何设置minDate,maxDate,dateFormat和其他选项 . 请帮帮我 .

码:

<dp-date-picker></dp-date-picker>

1 回答

  • 2

    你可以在component.ts中创建一个配置对象,如下所示,

    constructor() {}
      config = {
        firstDayOfWeek: 'su',
        monthFormat: 'MMM, YYYY',
        disableKeypress: false,
        allowMultiSelect: false,
        closeOnSelect: undefined,
        closeOnSelectDelay: 100,
        onOpenDelay: 0,
        weekDayFormat: 'ddd',
        appendTo: document.body,
        drops: 'down',
        opens: 'right',
        showNearMonthDays: true,
        showWeekNumbers: false,
        enableMonthSelector: true,
        format: "YYYY-MM-DD HH:mm",
        yearFormat: 'YYYY',
        showGoToCurrent: true,
        dayBtnFormat: 'DD',
        monthBtnFormat: 'MMM',
        hours12Format: 'hh',
        hours24Format: 'HH',
        meridiemFormat: 'A',
        minutesFormat: 'mm',
        minutesInterval: 1,
        secondsFormat: 'ss',
        secondsInterval: 1,
        showSeconds: false,
        showTwentyFourHours: true,
        timeSeparator: ':',
        multipleYearsNavigateBy: 10,
        showMultipleYearsNavigation: false,
        locale: 'zh-cn',
        // min:'2017-08-29 15:50',
        // minTime:'2017-08-29 15:50'
      };
    

    并在组件中引用,

    <dp-date-picker  theme="dp-material" [(ngModel)]="value" mode='daytime' [config]='config'
         (ngModelChange)="validatorsChanged()"
          [placeholder]="placeholder" [mode]='mode' #datePicker> 
      </dp-date-picker>
    

相关问题