Вы можете попробовать это решение
Я создал демо на stackblitz
Момент установки - npm install moment --save
import moment from 'moment';
код файла ts
atAdminName: FormGroup;
constructor(private fb: FormBuilder) {
this.atAdminName = this.fb.group({
date1: new FormControl(new Date(), Validators.required),
})
}
onFormSubmit() {
let newdateValue = moment(this.atAdminName.get('date1').value).format("DD-MM-YYYY");
this.atAdminName.get('date1').setValue(newdateValue);
console.log(this.atAdminName.value);
}
/**
* This method is change date format.
*/
dateFormat(date, controlType: string) {
this.atAdminName.get(controlType).setValue(moment(date).format("DD-MM-YYYY"));
}
html код файла
<form [formGroup]="atAdminName" (ngSubmit)="onFormSubmit()">
<div class="row">
<div class="col-md-6">
<label style="font-size: 18px">
From :
</label>
<mat-form-field>
<input (dateChange)="dateFormat($event.value,'date1')" matInput [matDatepicker]="picker1" formControlName="date1" style="font-size:18px">
<mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
<mat-datepicker #picker1></mat-datepicker>
</mat-form-field>
<br>
</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary">Show Report</button>
<button type="button" class="btn btn-default waves-effect">Reset</button>
</div>
</form>