【问题标题】:ng2-datepicker options not workingng2-datepicker 选项不起作用
【发布时间】:2017-05-01 14:39:44
【问题描述】:

我正在尝试将ng2-datepicker 集成到我的项目中。

在我尝试使用这些选项之前,它运行良好。根据文档,我可以使用属性绑定将选项传递给组件。所以我尝试自定义格式:

<ng2-datepicker [(ngModel)]="date" viewFormat="DD-MM-YYYY" name="date"></ng2-datepicker>

但是日期仍然以错误的格式显示(根据文档,这不是默认格式)。

我还尝试使用opened 选项默认打开日历,但它也不起作用。

我查看了 github 上的引用问题,没有人提到这个问题,这很明显。这让我觉得我误解了什么。

有什么想法吗?

【问题讨论】:

    标签: html angular ng2-datepicker


    【解决方案1】:

    文档不是最新的。现在,我们可以使用“options”属性传递选项。

    mycomponent.html 中:

    <ng2-datepicker [(ngModel)]="date" name="date" [options]="calendarOptions"></ng2-datepicker>
    

    mycomponent.ts 中:

    export class MyComponent implements OnInit {
      calendarOptions = {
        format: "DD-MM-YYYY",
        firstWeekdaySunday: false
      };
    

    【讨论】:

      【解决方案2】:
      this.datepickerOptions = new DatePickerOptions({
                format: 'DD-MM-YYYY'
       });
      

      在 HTML 中使用

      < ng2-datepicker name="dateExpires" [options]="datepickerOptions ">
      

      【讨论】:

        【解决方案3】:
        <ng-datepicker [options]="options"> </ng-datepicker>
        

        【讨论】:

          猜你喜欢
          • 2017-02-16
          • 1970-01-01
          • 2011-07-22
          • 1970-01-01
          • 2017-11-07
          • 2010-10-25
          • 2017-03-23
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多