Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material - embed date picker on page load / html tag

I've a requirement in which the material datepicker (the actual datepicker itself not the icon) has to be displayed in the page.

The page should always displays the datepicker rather than clicking on the icon.

Could someone help / guide me on this.

enter image description here

like image 487
mperle Avatar asked Dec 12 '25 06:12

mperle


1 Answers

I was facing the same problem but unfortunately <mat-datepicker opened="true" #picker></mat-datepicker> doesn't work.

I have analyzed the source code as well, seems they don't handle this scenario or not working.

What I have done to make this work is to give focus to the element and go ahead and open from that.

 <input matInput id="matInputEle" [matDatepicker]="picker" (focus)="picker.open()" >

add a function inside your .ts

ngOnInit() { 
   setTimeout(()=>{
        document.getElementById("matInputEle").focus();
   },1);
}

Hope this helps.

We need to wait for this issue got fixed in Angular material until I will go with this.

like image 179
Karthikvenkat86 Avatar answered Dec 15 '25 09:12

Karthikvenkat86



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!