@switch (view) {
@case (CalendarView.Month) {
}
@case (CalendarView.Week) {
}
@case (CalendarView.Day) {
}
}
`,
})
export class MyComponent {
readonly CalendarView = CalendarView;
viewDate = new Date();
events: CalendarEvent[] = [
{
start: new Date(),
title: 'An event',
},
];
setView(view: CalendarView) {
this.view = view;
}
}
```
--------------------------------
### Switch Calendar View
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/kitchen-sink/template.html
Conditionally renders content based on the current calendar view (Month, Week, Day).
```html
@switch (view) {
@case (CalendarView.Month) { }
@case (CalendarView.Week) { }
@case (CalendarView.Day) { }
}
```
--------------------------------
### Display Current View Title
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/min-max-date/template.html
Use the 'calendarDate' pipe to format the current view's title. Specify the view type and locale for correct formatting.
```html
{{ viewDate | calendarDate:(view + 'ViewTitle'):'en' }}
```
--------------------------------
### Pre-render Hooks for View Customization
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
Utilize `beforeViewRender` outputs to execute logic before a view is painted. This allows for dynamic modification of event data, such as adding CSS classes or custom metadata, without altering the original events array.
```typescript
import {
CalendarMonthViewBeforeRenderEvent,
CalendarWeekViewBeforeRenderEvent,
CalendarDayViewBeforeRenderEvent,
} from 'angular-calendar';
// Month: color weekend cells
beforeMonthViewRender(event: CalendarMonthViewBeforeRenderEvent): void {
event.body.forEach(day => {
if ([0, 6].includes(day.date.getDay())) {
day.cssClass = 'weekend';
}
});
}
// Week/Day: highlight business-hours segments
beforeWeekViewRender(event: CalendarWeekViewBeforeRenderEvent): void {
event.hourColumns.forEach(col =>
col.hours.forEach(h =>
h.segments.forEach(seg => {
const h = seg.date.getHours();
if (h < 9 || h >= 18) seg.cssClass = 'off-hours';
})
)
);
}
```
```html
```
--------------------------------
### Display Event Count and Date
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/group-similar-events/template.html
Conditionally displays the total badge count for a day if it's greater than zero, followed by the formatted date for the month view.
```html
@if (day.badgeTotal > 0) { {{ day.badgeTotal }} } {{ day.date | calendarDate:'monthViewDayNumber':locale }}
```
--------------------------------
### Display Calendar View Title
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/kitchen-sink/template.html
Formats the current view date for display as a title. Uses the 'calendarDate' pipe with 'en' locale.
```html
```
--------------------------------
### Iterate Over Day Events
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/context-menu/template.html
Iterates over the events associated with a specific day. This is a placeholder and likely intended to contain further event rendering logic.
```html
@for (event of day.events; track event) {
}
```
--------------------------------
### mwlCalendarToday Directive
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
Jump to the current date by attaching this directive to a clickable element. It emits `startOfDay(new Date())` when clicked and accepts a two-way `[(viewDate)]` binding.
```APIDOC
## mwlCalendarToday
### Description
Emits `startOfDay(new Date())` when clicked; accepts two-way `[(viewDate)]` binding.
### Inputs
- **viewDate** (Date) - Required for two-way binding
### Outputs
- **viewDateChange** (EventEmitter)
```
--------------------------------
### Iterate Over Event Groups
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/group-similar-events/template.html
Iterates over event groups for a given day and displays the length of the second event in each group. This is useful for scenarios where events are batched or grouped.
```html
@for (group of day.eventGroups; track group) { {{ group[1].length }} }
```
--------------------------------
### Display Hour Column Events
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/day-view-scheduler/day-view-scheduler.component.html
Renders events within hour columns. It iterates through hours and their segments, and also through column events.
```html
@if (view.hourColumns.length > 0) {
@for ( hour of view.hourColumns[0].hours; track hour.segments[0].date.toISOString(); let odd = $odd ) {
@for (segment of hour.segments; track segment.date.toISOString()) { }
}
}
@for ( column of view.hourColumns; track column.hours[0] ? column.hours[0].segments[0].date.toISOString() : column ) {
@for ( timeEvent of column.events; track timeEvent.event.id ?? timeEvent.event ) {
@if ( timeEvent.event?.resizable?.beforeStart && !timeEvent.startsBeforeDay ) {
} @if ( timeEvent.event?.resizable?.afterEnd && !timeEvent.endsAfterDay ) {
}
} @for ( hour of column.hours; track hour.segments[0].date.toISOString(); let odd = $odd ) {
@for ( segment of hour.segments; track segment.date.toISOString() ) { }
}
}
```
--------------------------------
### Custom Date Formatting with `CalendarDateFormatter`
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
Extend `CalendarDateFormatter` and override methods like `monthViewColumnHeader`, `weekViewHour`, and `dayViewHour` to customize how dates are displayed. Provide your custom formatter via DI.
```typescript
import { Injectable } from '@angular/core';
import { CalendarDateFormatter, DateFormatterParams } from 'angular-calendar';
import { formatDate } from '@angular/common';
@Injectable()
export class ShortDayFormatter extends CalendarDateFormatter {
// Show abbreviated weekday names in the month header
public monthViewColumnHeader({ date, locale }: DateFormatterParams): string {
return formatDate(date, 'EEE', locale); // 'Mon', 'Tue', ...
}
// 24-hour clock in week/day time labels
public weekViewHour({ date, locale }: DateFormatterParams): string {
return formatDate(date, 'HH:mm', locale);
}
public dayViewHour({ date, locale }: DateFormatterParams): string {
return formatDate(date, 'HH:mm', locale);
}
}
// Wire it up:
providers: [
provideCalendar(
{ provide: DateAdapter, useFactory: adapterFactory },
{ dateFormatter: { provide: CalendarDateFormatter, useClass: ShortDayFormatter } },
),
]
```
--------------------------------
### Display Day Number in Month View
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/custom-templates/template.html
Displays the date number for a given day, formatted according to the current locale. This is a standard element for month views.
```html
{{ day.date | calendarDate:'monthViewDayNumber':locale }}
```
--------------------------------
### Switching Calendar Views
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/exclude-days/template.html
This snippet shows the basic structure for switching between month, week, and day views in the Angular Calendar component using a switch statement.
```html
@switch (view) {
@case ('month') { }
@case ('week') { }
@case ('day') { }
}
```
--------------------------------
### Display Event Count Text
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/custom-templates/template.html
Shows the total number of events scheduled for a specific day. This provides a textual summary of events.
```html
There are {{ day.events.length }} events on this day
```
--------------------------------
### Expand Recurring Events with rrule and beforeViewRender
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
Combine the rrule library with the beforeViewRender hook to dynamically generate CalendarEvent instances for recurring events based on the currently visible period. This avoids pre-generating all occurrences.
```typescript
import { RRule } from 'rrule';
import { CalendarMonthViewBeforeRenderEvent, CalendarEvent } from 'angular-calendar';
import { ViewPeriod } from 'calendar-utils';
recurringRules = [
{ title: 'Weekly standup', color: { primary: '#1e90ff', secondary: '#D1E8FF' },
rrule: { freq: RRule.WEEKLY, byweekday: [RRule.MO, RRule.WE, RRule.FR] } },
{ title: 'Monthly review', color: { primary: '#e3bc08', secondary: '#FDF1BA' },
rrule: { freq: RRule.MONTHLY, bymonthday: 1 } },
];
calendarEvents: CalendarEvent[] = [];
private currentPeriod: ViewPeriod;
updateCalendarEvents(renderEvent: CalendarMonthViewBeforeRenderEvent): void {
const { start, end } = renderEvent.period;
if (
this.currentPeriod &&
this.currentPeriod.start.getTime() === start.getTime() &&
this.currentPeriod.end.getTime() === end.getTime()
) return; // already computed for this period
this.currentPeriod = renderEvent.period;
this.calendarEvents = [];
this.recurringRules.forEach(({ title, color, rrule }) => {
const rule = new RRule({ ...rrule, dtstart: start, until: end });
rule.all().forEach(date => {
this.calendarEvents.push({ title, color, start: date });
});
});
}
```
```html
```
--------------------------------
### mwlCalendarPreviousView Directive
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
Navigate to the previous period (day, week, or month) by attaching this directive to a clickable element. It emits a new `viewDate` one period earlier and respects `excludeDays` and `daysInWeek` inputs.
```APIDOC
## mwlCalendarPreviousView
### Description
Attaches to any clickable element and emits a new `viewDate` one period earlier. Handles month, week, and day views, and respects `excludeDays` and custom `daysInWeek`.
### Inputs
- **view** (CalendarView | 'month' | 'week' | 'day') - Required
- **viewDate** (Date) - Required
- **excludeDays** (number[]) - Optional, default []
- **daysInWeek** (number) - Optional
### Outputs
- **viewDateChange** (EventEmitter)
```
--------------------------------
### mwlCalendarNextView Directive
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
Advance the calendar to the next period (day, week, or month) by attaching this directive to a clickable element. It mirrors `mwlCalendarPreviousView` and emits a new `viewDate` one period forward.
```APIDOC
## mwlCalendarNextView
### Description
Mirror of `mwlCalendarPreviousView`, advances the calendar one period forward.
### Inputs
- **view** (CalendarView | 'month' | 'week' | 'day') - Required
- **viewDate** (Date) - Required
- **excludeDays** (number[]) - Optional, default []
- **daysInWeek** (number) - Optional
### Outputs
- **viewDateChange** (EventEmitter)
```
--------------------------------
### Watch Mode Tests
Source: https://github.com/mattlewis92/angular-calendar/blob/main/README.md
Continuously runs tests as code changes are detected, useful for TDD workflows.
```bash
pnpm test:watch
```
--------------------------------
### Display External Events in Month View
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/draggable-external-events/template.html
Iterates through external events and displays their titles. Use this to show a list of events that can be dragged into the calendar.
```html
@if (externalEvents.length === 0) {
_No events added_
} @else {
@for (event of externalEvents; track event) {
* [{{ event.title }}](javascript:;)
}
}
```
--------------------------------
### Format Week View Column Header
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/context-menu/template.html
Formats the date to be displayed as a column header in the week view.
```html
{{ day.date | calendarDate:'weekViewColumnHeader':locale }}
```
--------------------------------
### Display Event Count in Month View
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/custom-templates/template.html
Conditionally displays the number of events for a day if it's greater than zero. This is useful for visually indicating days with events.
```html
@if (day.badgeTotal > 0) { {{ day.badgeTotal }} }
```
--------------------------------
### Event Action Modal Content
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/kitchen-sink/template.html
Displays information about an event action that occurred, including the action type and the event details in JSON format.
```html
##### Event action occurred
×
Action:
{{ modalData?.action }}
Event:
{{ modalData?.event | json }}
OK
```
--------------------------------
### Display All-Day Events
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/day-view-scheduler/day-view-scheduler.component.html
Conditionally displays all-day event rows if any exist. Iterates through days and then through event rows.
```html
@if (view.allDayEventRows.length > 0) {
@for (day of days; track day.date.toISOString()) {
}
@for (eventRow of view.allDayEventRows; track eventRow.id) {
@for ( allDayEvent of eventRow.row; track allDayEvent.event.id ?? allDayEvent.event ) {
}
}
}
```
--------------------------------
### Include angular-calendar CSS
Source: https://github.com/mattlewis92/angular-calendar/blob/main/README.md
Import the angular-calendar CSS file into your application's global styles. This ensures the calendar components are styled correctly.
```css
/* angular-cli file: src/styles.css */
@import "../node_modules/angular-calendar/css/angular-calendar.css";
```
--------------------------------
### Format Calendar Dates and View Titles
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
The `calendarDate` pipe formats dates and view titles according to locale and specified view methods. It utilizes the injected `CalendarDateFormatter` for locale-aware string generation.
```html
{{ viewDate | calendarDate:'monthViewTitle':'en' }}
{{ viewDate | calendarDate:'weekViewTitle':'en':1 }}
{{ viewDate | calendarDate:'dayViewTitle':'fr' }}
```
--------------------------------
### Calendar View Switcher
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/draggable-external-events/template.html
A switch statement to handle different calendar views (Month, Week, Day). This is a common pattern for managing view changes in calendar components.
```html
@switch (view) {
@case (CalendarView.Month) {
}
@case (CalendarView.Week) {
}
@case (CalendarView.Day) {
}
}
```
--------------------------------
### Format Week View Column Subheader
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/context-menu/template.html
Formats the date for the subheader of a column in the week view.
```html
{{ day.date | calendarDate:'weekViewColumnSubHeader':locale }}
```
--------------------------------
### Handle Day and Time Slot Clicks in Angular Calendar
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/clickable-days/template.html
Use template syntax to display information about the clicked date or column. This requires the `clickedDate` and `clickedColumn` variables to be defined and updated by calendar events.
```html
@if (clickedDate) {
**You clicked on this time: {{ clickedDate | date:'medium' }}**
}
@if (clickedColumn !== undefined) {
**You clicked on this column: {{ clickedColumn }}**
}
```
--------------------------------
### calendarDate Pipe
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
Format view titles and dates using the `calendarDate` pipe. It delegates to the injected `CalendarDateFormatter` to produce locale-aware strings for view titles and hour labels.
```APIDOC
## calendarDate Pipe
### Description
Delegates to the injected `CalendarDateFormatter` to produce locale-aware strings for view titles and hour labels.
### Usage
`date | calendarDate : method : locale? : weekStartsOn? : excludeDays? : daysInWeek?`
### Available methods:
- `monthViewTitle`, `monthViewColumnHeader`, `monthViewDayNumber`
- `weekViewTitle`, `weekViewColumnHeader`, `weekViewColumnSubHeader`, `weekViewHour`
- `dayViewTitle`, `dayViewHour`
### Examples:
```html
{{ viewDate | calendarDate:'monthViewTitle':'en' }}
{{ viewDate | calendarDate:'weekViewTitle':'en':1 }}
{{ viewDate | calendarDate:'dayViewTitle':'fr' }}
```
```
--------------------------------
### Navigate to Previous Calendar Period
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
Use the `mwlCalendarPreviousView` directive on a clickable element to navigate to the previous calendar period (month, week, or day). It respects `excludeDays` and `daysInWeek` inputs.
```html
```
--------------------------------
### Navigate to Next Calendar Period
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
The `mwlCalendarNextView` directive, when attached to a clickable element, advances the calendar to the next period (month, week, or day). It functions similarly to `mwlCalendarPreviousView`.
```html
```
--------------------------------
### Manual Calendar Re-render with RxJS Subject
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
Use an RxJS Subject to manually trigger re-renders of the calendar, especially useful with ChangeDetectionStrategy.OnPush. Emit from the subject after mutating the events array in-place.
```typescript
import { Subject } from 'rxjs';
import { CalendarEvent, CalendarMonthViewComponent } from 'angular-calendar';
@Component({
imports: [CalendarMonthViewComponent],
template: ``,
})
export class MyComponent {
viewDate = new Date();
refresh = new Subject();
events: CalendarEvent[] = [];
addEvent(): void {
// Mutate in place – change detection won't pick this up with OnPush
this.events.push({ start: new Date(), title: 'Late addition' });
this.refresh.next(); // triggers re-render
}
updateEventTitle(event: CalendarEvent, newTitle: string): void {
event.title = newTitle;
this.refresh.next();
}
}
```
--------------------------------
### Format Day View Hour
Source: https://github.com/mattlewis92/angular-calendar/blob/main/projects/demos/app/demo-modules/context-menu/template.html
Formats a time segment's date to display as an hour in the day view.
```html
{{ segment.date | calendarDate: 'dayViewHour':locale }}
```
--------------------------------
### Define CalendarEvent Interface Data
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
Defines the structure for calendar events, including properties for title, start/end dates, all-day status, colors, and custom actions. Use this interface to model event data for the calendar.
```typescript
import {
CalendarEvent,
} from 'angular-calendar';
import {
startOfDay,
endOfDay,
addHours,
subDays,
} from 'date-fns';
const events: CalendarEvent[] = [
{
id: 1,
title: 'All-day event',
start: startOfDay(new Date()),
end: endOfDay(new Date()),
allDay: true,
color: { primary: '#1e90ff', secondary: '#D1E8FF' },
cssClass: 'my-custom-class',
},
{
id: 2,
title: 'Timed event with drag & resize',
start: addHours(startOfDay(new Date()), 9),
end: addHours(startOfDay(new Date()), 11),
draggable: true,
resizable: { beforeStart: true, afterEnd: true },
actions: [
{
label: '',
a11yLabel: 'Edit',
onClick: ({ event }) => console.log('Edit', event),
},
{
label: '',
a11yLabel: 'Delete',
onClick: ({ event }) => { /* remove from array */ },
},
],
meta: { userId: 42 }, // arbitrary metadata
},
{
title: 'Multi-day spanning event',
start: subDays(new Date(), 2),
end: addHours(new Date(), 48),
color: { primary: '#ad2121', secondary: '#FAE3E3' },
},
];
```
--------------------------------
### Jump to Today's Date
Source: https://context7.com/mattlewis92/angular-calendar/llms.txt
The `mwlCalendarToday` directive provides a simple way to reset the calendar view to the current date. It can be used with a two-way binding to `viewDate` or by listening to the `viewDateChange` event.
```html
```