我有一个表格,我在其中发送日期,而在 API 中收到它的时间晚了一天。
这是我的html模板:
<div class="container">
<form #form="ngForm" autocomplete="off" (ngSubmit)="onSubmit(form)">
<mat-form-field appearance="fill">
<mat-label>Start date</mat-label>
<input name="rentalstartdate" matInput [matDatepicker]="picker" #startdate="ngModel" [(ngModel)]="service.formData.rentalstartdate" required>
<div class="alert alert-danger" *ngIf="service.formData.rentalstartdate.touched && !service.formData.rentalstartdate.valid">Start date is required</div>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
<br>
<mat-form-field appearance="fill">
<mat-label>End date</mat-label>
<input name="rentalenddate" matInput [matDatepicker]="picker1" #enddate="ngModel" [(ngModel)]="service.formData.rentalenddate" required>
<div class="alert alert-danger" *ngIf="service.formData.rentalenddate.touched && !service.formData.rentalenddate.valid">End date is required</div>
<mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
<mat-datepicker #picker1></mat-datepicker>
</mat-form-field>
<button mat-raised-button color="primary" type="submit" [disabled]="!form.valid">Book a car</button>
</form>
</div>
这是我在 component.ts 中调用服务方法的方法:
onSubmit(form: NgForm) {
this.CreateReservation(form);
}
CreateReservation(form: NgForm) {
this.service.CreateReservation().subscribe(
res => {
this.resetForm(form);
},
err => {
}
)
}
这是我的 service.ts
formData: Reservation;
CreateReservation() {
return this.http.post(this.rootURL + '/reservation/createreservation', this.formData);
}
我怎样才能在不落后一天的情况下发送日期?