首页 > 解决方案 > Angular10 OWL 日期时间预设一个日期和时间

问题描述

我正在使用 OWL 日期时间选择器。我想要的是能够设置我自己的日期时间,以便预先填写它。这是我使用的代码:

 <input [owlDateTime]="dt1" placeholder="End Date Time" formControlName="endDateTime">
 <span [owlDateTimeTrigger]="dt1"><i class="fa fa-calendar"></i></span>
 <owl-date-time #dt1></owl-date-time>

我也试过这行代码,但它在 Angular10 中不起作用:

<owl-date-time-inline [(ngModel)]="selectedMoment"></owl-date-time-inline>

有人知道我怎么能做到这一点吗?

多谢

标签: angulardatetimepicker

解决方案


如果您像我一样使用反应式表单,只需设置:

  this.rForm = this.fb.group({
    startDateTime: [ new Date(//Value of database in here), Validators.required],
  });

如果您不使用反应形式:

在 ts 文件中:

public selectedMoment = new Date('Value of database here');

并在您的 HTML 文件中将 ngModel 添加到 owl 的输入中!


推荐阅读