Always showing the calendar from datepicker - Angular

谁说我不能喝 提交于 2019-12-24 04:17:12

问题


I need to have the datepicker in Angular always visible. The calendar will be always visible without the dependency on the button (don't need to click on the button)

example

Source .html

<mat-form-field>
  <input matInput [matDatepicker]="picker" placeholder="Choose a date">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

回答1:


You can use mat-calendar for this:

<mat-calendar [selected]="selectedDate" (selectedChange)="selectedDate = $event"></mat-calendar>



回答2:


You can add opened="true" to the datepicker.

You can use code like this :

<mat-form-field>
  <input matInput [matDatepicker]="picker" placeholder="Choose a date">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker class="fixed-open" #picker opened="true"></mat-datepicker>
</mat-form-field>

Working example : https://stackblitz.com/edit/angular-ysspzm?file=app%2Fdatepicker-overview-example.html

Documentation : https://material.angular.io/components/datepicker/api




回答3:


you can using opened="true" for this.

<mat-form-field>
  <input matInput [matDatepicker]="picker" placeholder="Choose a date">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker opened="true"></mat-datepicker>
</mat-form-field>


来源:https://stackoverflow.com/questions/51170663/always-showing-the-calendar-from-datepicker-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!