-1

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-

enter image description here

Techdive
  • 997
  • 3
  • 24
  • 49

1 Answers1

0

I solved my issue by putting -

 constructor(
       this.onlineDate = new FormControl(new Date(new Date().setDate(new Date().getDate() + 1)));

  }
Techdive
  • 997
  • 3
  • 24
  • 49
  • `today=new Date();onlineDate=new FormControl(new Date(this.today.setHours(0,0,0,0)-24*60*60*1000))` – Eliseo Sep 02 '22 at 09:44