【发布时间】:2018-03-28 20:52:01
【问题描述】:
我有一个角度为 4 的输入类型日期,并且我有 2 个日期选择器字段,例如,当我从 23.03.2018 选择到 29.03.2018 时,当我按下保存时,日期取的是今天的日期,这不会改变,这怎么可能发生。我尝试使用 ngModelChange 来更改该值,但在数据库中它发送的就像今天的日期一样...您可以在下面找到代码。
<app-input-field orientation="top" label="Beginning Date">
<input [min]="today" type="date" step="1" [(ngModel)]="newCreate" style="width:250px">
</app-input-field>
<br>
<app-input-field orientation="top" label="Ending Date">
<input [min]="today" type="date" step="1"
[(ngModel)]="newEnd" style="width: 250px;">
</app-input-field>
这是 TS 文件
newCreate: string = new Date().toISOString().substring(0, 19);
newEnd: string = new Date().toISOString().substring(0, 19);
这是我点击保存的时候。
save() {
// How to convert here because when is saved it is saved like date
//with minutes and everything else.
this.newProject.name = this.newProjectName;
this.newProject.state = this.newState;
this.newProject.type = this.newType;
this.newProject.created = new Date(this.newCreate);
this.newProject.ending = new Date(this.newEnd);
this.newProject.category = this.category;
this.newProject.subProjectIds = this.subProjectIds;
this.store.dispatch(new UpsertProjectAction(this.newProject));
this.dialogRef.close(this.newProject);
【问题讨论】:
-
你可能希望用你正在使用的库来标记它。不同的日期选择器组件具有不同的行为。例如,有些要求值是
Date对象而不是字符串。另外,您需要检查Converting string to date in js
标签: angular typescript