angular - 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>
有人知道我怎么能做到这一点吗?
多谢
解决方案
如果您像我一样使用反应式表单,只需设置:
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 的输入中!
推荐阅读
- python - 两个语句返回两个不同结果时的MYSQL存储过程优化
- flutter - 在 Flutter 中部署 ML 分类模型
- vue.js - 似乎无法通过 Vue 中的道具将数据传递给组件
- ios - 如何运行和编译 SPM 以查看结果
- python - 将元组元组转换(和反转)为字典时出错
- java - 无法在 Visual Studio 代码中使用引用的库编译 java 程序,错误:找不到符号
- javascript - 对从屏幕上填充的 api 获取的数据中的特定单词进行样式设置
- windows - Windows 上的 GCC/G++-11
- azure-rm - 如何使用二头肌将父资源名称引用到模块内的资源
- tinymce - TinyMCE:Span Tag 不能包含 a、i、br 元素。不是继续跨度,而是拆分