首页 文章

ng2-datepicker选项不起作用

提问于
浏览
2

我想在我的项目中集成ng2-datepicker .

它工作正常,直到我尝试使用这些选项 . 根据文档,我可以使用属性绑定将选项传递给组件 . 所以我尝试自定义格式:

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

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

我还尝试使用选项 opened 默认打开日历,但它也无效 .

我查看了github上引用的问题,没有人提到这个问题,这个问题很明显 . 这让我觉得我误解了一些东西 .

有任何想法吗?

2 回答

  • 4

    文档不是最新的 . 现在,我们可以使用“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
      };
    
  • 1
    this.datepickerOptions = new DatePickerOptions({
              format: 'DD-MM-YYYY'
     });
    

    在HTML中使用

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

相关问题