【发布时间】:2021-02-28 15:07:07
【问题描述】:
<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;
}
这个模板驱动的“表单”如何在 dom 输入部分设置今天的日期?我必须在这里使用[(ngModel)]。
【问题讨论】:
-
我认为初始化应该在 OnInit 方法中完成,而不是在构造函数中!