Angular Calendar Custom Header

You can customize how the header of calendar looks and how the components are arranged. Besides that you can also add custom functionality, like a segmented control that lets people switch between week and month view.

Use the headerTemplate option for passing a custom template. There are predefined components - shorthands if you will - that can be used to assemble the header:

  • Navigation component - <mbsc-calendar-nav></mbsc-calendar-nav>
  • Today button - <mbsc-calendar-today></mbsc-calendar-today>
  • Previous month button - <mbsc-calendar-prev></mbsc-calendar-prev>
  • Next month button - <mbsc-calendar-next></mbsc-calendar-next>
Get started with this example

Demo

Default header

The default header contains the two arrows on the far-right for previous and next months, while the current month indicator with the mbsc-calendar-nav component is placed to the far-left.

<mbsc-datepicker
    [controls]="['calendar']"
    calendarType="week"
    [calendarSize]="2">
</mbsc-datepicker>
Custom header arrangement

You can reorder the controls and place the mbsc-calendar-nav in the middle with the two arrows - mbsc-calendar-prev and mbsc-calendar-next - to the sides.

<mbsc-datepicker
    [controls]="['calendar']"
    [calendarHeaderTemplate]="calendarHeader">
    <ng-template #calendarHeader>
        <mbsc-calendar-prev class="custom-prev"></mbsc-calendar-prev>
        <mbsc-calendar-nav class="custom-nav"></mbsc-calendar-nav>
        <mbsc-calendar-next class="custom-next"></mbsc-calendar-next>
    </ng-template>
</mbsc-datepicker>
Add a today button

You can also add a custom component, like a mbsc-calendar-today button.

<mbsc-datepicker
    [controls]="['calendar']"
    [calendarHeaderTemplate]="calendarHeader">
    <ng-template #calendarHeader>
        <mbsc-calendar-nav></mbsc-calendar-nav>
        <div class="custom-buttons">
            <mbsc-calendar-prev></mbsc-calendar-prev>
            <mbsc-calendar-today></mbsc-calendar-today>
            <mbsc-calendar-next></mbsc-calendar-next>
    </ng-template>
</mbsc-datepicker>
Switch between week and month view

Use a segmented component for creating a view switcher.

html<mbsc-datepicker
    [controls]="['calendar']"
    [calendarType]="calendarType"
    [calendarSize]="2"
    [calendarHeaderTemplate]="calendarHeader">
    <ng-template #calendarHeader>
        <mbsc-calendar-nav class="custom-view-nav"></mbsc-calendar-nav>
        <div class="custom-view">
            <mbsc-segmented-group [(ngModel)]="view" (change)="changeView()">
                <mbsc-segmented value="week" icon="material-date-range"></mbsc-segmented>
                <mbsc-segmented value="month" icon="material-event-note"></mbsc-segmented>
            </mbsc-segmented-group>
        </div>
        <mbsc-calendar-prev></mbsc-calendar-prev>
        <mbsc-calendar-next></mbsc-calendar-next>
    </ng-template>
</mbsc-datepicker>
tsview = 'week';
changeView() {
    setTimeout(() => {
        switch (this.view) {
            case 'week':
                this.calendarType = 'week';
                break;
            case 'month':
                this.calendarType = 'month';
                break;
        }
    });
}
Preview the selection

Above all that you can give instructions or show the selected {value} in the header

<mbsc-datepicker
    [controls]="['calendar']"
    calendarType="week"
    [calendarSize]="2"
    headerText="You selected {value}">
</mbsc-datepicker>

Duplicate Session

You have signed in on a different machine. To keep everything in sync, you have been signed out of this session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.

Duplicate Session

We noticed you are logged in on a different machine and have closed your old session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.