0
    <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)]。

4

2 回答 2

1

请试试这个,

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>

测试组件.ts

callListRequestOb={
    from_date: new Date()
}
于 2020-11-17T11:52:59.397 回答
0

在 CallListModel.ts 文件中,我将 from_date 和 to_date 类型更改为 Date。

export class CallListRequestModel{
    from_date: Date;
    to_date: Date;
 }

然后在构造函数中,我写了这个并且它正在工作。

this.callListRequestOb.from_date = new Date();

谢谢大家帮助我。

于 2020-11-18T05:50:18.387 回答