Last active
February 10, 2022 10:13
-
-
Save jhades/0509b6be014c3e8a6d93d2cc1d87c5a8 to your computer and use it in GitHub Desktop.
Angular Material Datepicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-form-field appearance="outline"> | |
<input matInput formControlName="releasedAt"> | |
</mat-form-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-form-field appearance="outline"> | |
<input matInput formControlName="releasedAt" [matDatepicker]="releasedAtPicker"> | |
<mat-datepicker #releasedAtPicker> | |
</mat-datepicker> | |
</mat-form-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-form-field appearance="outline"> | |
<input matInput formControlName="releasedAt" [matDatepicker]="releasedAtPicker"> | |
<mat-datepicker-toggle matSuffix [for]="releasedAtPicker"> | |
</mat-datepicker-toggle> | |
<mat-datepicker #releasedAtPicker> | |
</mat-datepicker> | |
</mat-form-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-form-field appearance="outline"> | |
<input matInput formControlName="releasedAt" [matDatepicker]="releasedAtPicker"> | |
<mat-datepicker-toggle matPrefix [for]="releasedAtPicker"> | |
<mat-icon matDatepickerToggleIcon> | |
calendar_month | |
</mat-icon> | |
</mat-datepicker-toggle> | |
<mat-datepicker #releasedAtPicker> | |
</mat-datepicker> | |
</mat-form-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-form-field appearance="outline"> | |
<input matInput formControlName="releasedAt" | |
[matDatepicker]="releasedAtPicker" (click)="releasedAtPicker.open()"> | |
<mat-datepicker-toggle matSuffix [for]="releasedAtPicker"> | |
</mat-datepicker-toggle> | |
<mat-datepicker #releasedAtPicker> | |
</mat-datepicker> | |
</mat-form-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-form-field appearance="outline"> | |
<input matInput formControlName="releasedAt" disabled | |
[matDatepicker]="releasedAtPicker"> | |
<mat-datepicker-toggle matSuffix [for]="releasedAtPicker" [disabled]="false"> | |
</mat-datepicker-toggle> | |
<mat-datepicker #releasedAtPicker [disabled]="false"> | |
</mat-datepicker> | |
</mat-form-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-form-field appearance="outline"> | |
<input matInput formControlName="releasedAt" | |
[matDatepicker]="releasedAtPicker"> | |
<mat-datepicker-toggle matSuffix [for]="releasedAtPicker"> | |
</mat-datepicker-toggle> | |
<mat-datepicker #releasedAtPicker startView="year"> | |
</mat-datepicker> | |
</mat-form-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-form-field appearance="outline"> | |
<input matInput formControlName="releasedAt" | |
[matDatepicker]="releasedAtPicker"> | |
<mat-datepicker-toggle matSuffix [for]="releasedAtPicker"> | |
</mat-datepicker-toggle> | |
<mat-datepicker #releasedAtPicker [touchUi]="true"> | |
</mat-datepicker> | |
</mat-form-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-calendar [(selected)]="selectedDate"> | |
</mat-calendar> | |
<p>selected Date: {{selectedDate}}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-form-field appearance="outline"> | |
<input matInput formControlName="releasedAt" | |
[matDatepicker]="releasedAtPicker"> | |
<mat-datepicker-toggle matSuffix [for]="releasedAtPicker"> | |
</mat-datepicker-toggle> | |
<mat-datepicker #releasedAtPicker [startAt]="startDate"> | |
</mat-datepicker> | |
</mat-form-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-datepicker #releasedAtPicker color="accent"> | |
</mat-datepicker> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dateClass: MatCalendarCellClassFunction<Date> = (cellDate, view) => { | |
const date = cellDate.getDate(); | |
if (view == 'month') { | |
return (date == 1) ? 'highlight-date' : ""; | |
} | |
return ""; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-datepicker #releasedAtPicker [dateClass]="dateClass"> | |
</mat-datepicker> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-form-field appearance="outline"> | |
<input matInput formControlName="releasedAt" | |
[min]="minDate" | |
[max]="maxDate" | |
[matDatepicker]="releasedAtPicker"> | |
<mat-datepicker-toggle matSuffix [for]="releasedAtPicker"> | |
</mat-datepicker-toggle> | |
<mat-datepicker #releasedAtPicker> | |
</mat-datepicker> | |
</mat-form-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dateFilter: (date: Date | null) => boolean = | |
(date: Date | null) => { | |
if (!date) { | |
return false; | |
} | |
const day = date.getDay(); | |
return day == 1; // 1 means monday, 0 means sunday, etc. | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-form-field appearance="outline"> | |
<input matInput formControlName="releasedAt" | |
[matDatepickerFilter]="dateFilter" | |
[matDatepicker]="releasedAtPicker"> | |
<mat-datepicker-toggle matSuffix [for]="releasedAtPicker"> | |
</mat-datepicker-toggle> | |
<mat-datepicker #releasedAtPicker> | |
</mat-datepicker> | |
</mat-form-field> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment