Reputation: 1043
I want to update and make yesterday's date appear as the date in mat-datepicker.
I tried to implement it the following way but it was not successful. My code -
app.component.html
<mat-form-field class="example-full-width" [floatLabel]="hideLabel">
<input matInput [formControl]="onlineDate" name="onlineDate" [max]="currentDate"
[matDatepicker]="picker" required placeholder="Online Date "
autocomplete="off" />
<mat-datepicker-toggle matSuffix [for]="picker">
</mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
app.component.ts
export class ApplicantComponent implements OnInit, AfterViewInit {
onlineDate: FormControl;
currentDate = new Date();
today = new Date()
yesterday = new Date();
constructor(
this.onlineDate = new FormControl(this.yesterday.setDate(this.yesterday.getDate() - 1))
}
}
With the above code, I am unable to get any date in display. Screenshot for reference-
Upvotes: -1
Views: 490
Reputation: 1043
I solved my issue by putting -
constructor(
this.onlineDate = new FormControl(new Date(new Date().setDate(new Date().getDate() + 1)));
}
Upvotes: 0