I wanted to disable all past date before current date in Angular 6.0+ Calendar week view. https://stackblitz.com/edit/angular6-calendar
Asked
Active
Viewed 1,361 times
1
-
Please add some code of what you have done so far. – Mridul Feb 19 '20 at 09:17
-
https://stackblitz.com/edit/angular6-calendar – Nithin mm Feb 19 '20 at 09:23
-
Refer this example: https://mattlewis92.github.io/angular-calendar/#/min-max-date – NiK648 Feb 19 '20 at 09:46
1 Answers
0
Late and probably unneeded answer for OP at this point, but in case someone stumbles upon this answer on Google like me and still needs help, I found a solution on GitHub
The comment provided this solution:
In template.html add this
<mwl-calendar-week-view
// ...
(beforeViewRender)="beforeViewRender($event)"
>
</mwl-calendar-week-view>
In component.ts (put everything within the class):
// Define a minimum date (to disable everything in the past you can just write this)
minDate: Date = new Date();
// Validator function
dateIsValid(date: Date): boolean {
return date >= this.minDate;
}
// Event handler which you bind to the `<mwl-calendar-week-view>` component in the html template
beforeViewRender(body: CalendarWeekViewBeforeRenderEvent): void {
body.hourColumns.forEach(hourCol => {
hourCol.hours.forEach(hour => {
hour.segments.forEach(segment => {
if (!this.dateIsValid(segment.date)) {
segment.cssClass = 'cal-disabled';
}
});
});
});
}
In component.css
.cal-disabled {
background-color: #eee;
pointer-events: none;
}

Phlame
- 306
- 1
- 6
- 17