[英]How to change the date from angular material datepicker?
I have a date-picker from angular material.我有一个角度材料的日期选择器。 On click of some event, I'm getting the new date from api service.单击某个事件时,我会从 api 服务获取新日期。 How do I change the date on some click event?如何更改某些点击事件的日期?
By Default, I have some date.默认情况下,我有一些约会。 After click the submit button, there is some api handled(assume), on subscribing the response values there is a variable with date format.单击提交按钮后,有一些 api 处理(假设),在订阅响应值时有一个日期格式的变量。
How do I change the date on some click event?如何更改某些点击事件的日期?
<mat-form-field>
<input matInput [matDatepicker]="picker" placeholder="Choose a date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field> <br/>
<button (click)="dosomeaction()">Submit</button>
export class DatepickerOverviewExample {
dosomeaction = function(){
let date = "2018/09/04";
//assign the above date to the input field
}
}
You can do it like this你可以这样做
component.html组件.html
<mat-form-field>
<input matInput [matDatepicker]="picker"
[(ngModel)]="dateToPass"placeholder="Choose a date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field> <br/>
<button (click)="dosomeaction()">Submit</button>
component.ts组件.ts
export class DatepickerOverviewExample {
dateToPass;
dosomeaction(){
let date = new Date("2018/09/04");
//assign the above date to the input field
this.dateToPass = date;
}
}
Look at this Stackblitz , just set the date in ngModel
看看这个Stackblitz ,只需在ngModel
设置日期
export class DatepickerOverviewExample {
start_time: Date;
dosomeaction = function(){
start_time: new Date();
}
}
<input mdInput
name="start_time"
#start_time="ngModel"
date="true"
[(ngModel)]="start_time"
placeholder="Choose a date">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.