Javascript Mat日期选择器值自动选择
我正在创建提醒应用程序,无法在mat datepicker中设置日期(更像是预填充)。 我有一个目标Javascript Mat日期选择器值自动选择,javascript,html,angular,datepicker,angular-material,Javascript,Html,Angular,Datepicker,Angular Material,我正在创建提醒应用程序,无法在mat datepicker中设置日期(更像是预填充)。 我有一个目标 resObj = { "taskId": 230, "whenToDo": "2020-05-10T00:00:00.000+0000", "wherToGo": "CityHall", "whatTodo": "Talk to mentor" } 在.ts文件中,我将ngOnit()上日期的格式更改为2020年4月10日 this.doj =
resObj = {
"taskId": 230,
"whenToDo": "2020-05-10T00:00:00.000+0000",
"wherToGo": "CityHall",
"whatTodo": "Talk to mentor"
}
在.ts文件中,我将ngOnit()上日期的格式更改为2020年4月10日
this.doj = this.resObj.dojs
this.doj = new DatePipe('en-US').transform(this.resObj.dojs, 'dd/MM/yyyy')
在HTML中
<mat-form-field>
<input [(ngModel)]="doj" name="dojs" matInput [matDatepicker]="picker" placeholder="Date of Joining">
<mat-icon matSuffix>
<img src="../../../assets/images/icons/purple_icons/icon-calendar.png" (click)="picker.open()">
</mat-icon>
<mat-datepicker #picker touchUi></mat-datepicker>
</mat-form-field>
是否有一种方法可以设置上面的日期,当用户打开页面时在日期选择器中选择,并且应该禁用从“今天的日期和之前”开始的日期 您可以通过添加
[formControl]
来设置默认日期。
您可以设置禁用前几天的[min]
值
<mat-form-field>
<input [(ngModel)]="doj" name="dojs" matInput [matDatepicker]="picker" placeholder="Date of Joining"
[formControl]="defaultDate" [min]="minDate">
<mat-icon matSuffix>
<img src="../../../assets/images/icons/purple_icons/icon-calendar.png" (click)="picker.open()">
</mat-icon>
<mat-datepicker #picker touchUi></mat-datepicker>
</mat-form-field>
要禁用今天和过去的日子
minDate: Date;
ngOnInit() {
this.minDate = new Date();
this.minDate.setDate(this.minDate.getDate() + 1)
}
您想在代码中的某个位置设置默认日期(表示硬编码),并禁用日期之前的任何日期,包括今天的日期,对吗?如果是,默认日期应该是什么?@igg yes解散日期包括今天和今天之前,并且默认日期将是对象中的日期,即resObj->whenToDo中的日期。
minDate: Date;
ngOnInit() {
this.minDate = new Date();
this.minDate.setDate(this.minDate.getDate() + 1)
}