I am working on Mat date picker custom value. Here is my code which I am trying
<div class="form-group" *ngIf="selectVal.value == 'Date'">
<mat-form-field>
<input matInput [matDatepicker]="picker" (dateChange)="formatDate(dateValue.value)" #dateValue formControlName="assumptionValueInDatetime" class="form-control" placeholder="Choose a date" >
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
</div>
Here is my ts code. Here is the format I want 07-JUL-2020
formatDate(value) {
const months = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
let formatDate = ('0' + value.getDate()).slice(-2) + "-" + months[value.getMonth()] + "-" + (value.getFullYear());
return formatDate;
}
This is what my payload looks like:
initassumpationForm() {
this.assumptionDesignForm = this.fb.group({
assumptionValueInDatetime: this.formatDate(this.assumptionValueInDatetime)
});
}
Getting error as:
ERROR TypeError: Cannot read property 'getDate' of undefined