如何在输入部分设置默认日期?
How can I set the default date in input portion?
<mat-form-field>
<input matInput [matDatepicker]="picker1" placeholder="From date: mm-dd-yyyy"
name="from_date" [(ngModel)]="callListRequestOb.from_date" maxlength="150">
<mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
<mat-datepicker #picker1></mat-datepicker>
</mat-form-field
(.ts 文件)
constructor(
private modalService: NgbModal,
private aService: ApplicationService,
) {
this.callListRequestOb = new CallListRequestModel();
this.currentUser = JSON.parse(localStorage.getItem('currentUser'));
this.callListRequestOb.from_date = moment().format('MM-DD-YYYY');
this.callListRequestOb.to_date = moment().format('MM-DD-YYYY');
this.callListRequestOb.page_no = this.page;
this.callListRequestOb.row_per_page = this.pageSize;
}
这个模板驱动的 'form' 如何在 dom 输入部分设置今天的日期?我必须在这里使用[(ngModel)]。
请试试这个,
test.component.html
<mat-form-field>
<input matInput [matDatepicker]="picker1" placeholder="From date: mm-dd-yyyy"
name="from_date" [(ngModel)]="callListRequestOb.from_date" maxlength="150">
<mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
<mat-datepicker #picker1></mat-datepicker>
</mat-form-field>
test.component.ts
callListRequestOb={
from_date: new Date()
}
在 CallListModel.ts 文件中,我将 from_date & to_date 类型更改为日期。
export class CallListRequestModel{
from_date: Date;
to_date: Date;
}
然后在构造函数中,我写了这个并且它正在工作。
this.callListRequestOb.from_date = new Date();
谢谢大家的帮助。
<mat-form-field>
<input matInput [matDatepicker]="picker1" placeholder="From date: mm-dd-yyyy"
name="from_date" [(ngModel)]="callListRequestOb.from_date" maxlength="150">
<mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
<mat-datepicker #picker1></mat-datepicker>
</mat-form-field
(.ts 文件)
constructor(
private modalService: NgbModal,
private aService: ApplicationService,
) {
this.callListRequestOb = new CallListRequestModel();
this.currentUser = JSON.parse(localStorage.getItem('currentUser'));
this.callListRequestOb.from_date = moment().format('MM-DD-YYYY');
this.callListRequestOb.to_date = moment().format('MM-DD-YYYY');
this.callListRequestOb.page_no = this.page;
this.callListRequestOb.row_per_page = this.pageSize;
}
这个模板驱动的 'form' 如何在 dom 输入部分设置今天的日期?我必须在这里使用[(ngModel)]。
请试试这个,
test.component.html
<mat-form-field>
<input matInput [matDatepicker]="picker1" placeholder="From date: mm-dd-yyyy"
name="from_date" [(ngModel)]="callListRequestOb.from_date" maxlength="150">
<mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
<mat-datepicker #picker1></mat-datepicker>
</mat-form-field>
test.component.ts
callListRequestOb={
from_date: new Date()
}
在 CallListModel.ts 文件中,我将 from_date & to_date 类型更改为日期。
export class CallListRequestModel{
from_date: Date;
to_date: Date;
}
然后在构造函数中,我写了这个并且它正在工作。
this.callListRequestOb.from_date = new Date();
谢谢大家的帮助。