Используя formGroup
и HTML datepicker
import { FormGroup,FormControl} from '@angular/forms';
date;
testForm : FormGroup;
constructor(){
this.testForm = new FormGroup({
date:new FormControl(this.date),
setDate:new FormControl(),
})
}
setDatepicker(evt) {
var value= this.testForm.controls['setDate'].value
this.date=new Date(new Date(value).getTime())
this.testForm.controls['date'].setValue(this.date);
}
<form [formGroup]="testForm" >
<mat-form-field>
<input matInput type="date" placeholder=" date picker on blur" (blur)="setDatepicker($event)" formControlName="setDate">
</mat-form-field> <br>
<mat-form-field class="mr-sm-24" fxFlex (click)="open()" >
<input matInput [matDatepicker]="picker" placeholder="Date"
autocomplete="off"
name="date" formControlName="date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker [startAt]="date" #picker></mat-datepicker>
</mat-form-field>
</form>