将日期数组分配给ngx-mydatepicker disableDates

时间:2018-05-09 22:40:49

标签: angular typescript

我在项目中使用ngx-mydatepicker,我需要使用disableDates选项,它是ngx-mydatepicker自定义接口IMyDate的数组。我的日期是Date的数组。

示例:请参阅app.component.ts

Stackblitz Editor Example

TS

  //normally this comes from an API call.  They need to get
  //assigned to the disableDates below.
  invalidJsDates: Date[] = [new Date("2018-05-09"), new Date("2018-05-29")];

  myOptions: INgxMyDpOptions = {
      dateFormat: 'mm/dd/yyyy',
      //disableDates: this.invalidJsDates //need to convert this to array of IMyDate
  };

HTML

  <div class="input-group">
      <input class="form-control" style="float:none" placeholder="Select a date" ngx-mydatepicker name="mydate"
              [(ngModel)]="model" [options]="myOptions" #dp="ngx-mydatepicker"/>

      <span class="input-group-btn">
          <button type="button" class="btn btn-default" (click)="dp.clearDate()">
              <i class="glyphicon glyphicon-remove"></i> Clear
          </button>
          <button type="button" class="btn btn-default" (click)="dp.toggleCalendar()">
              <i class="glyphicon glyphicon-calendar"></i>Toggle
          </button>
      </span>
  </div>

0 个答案:

没有答案