---
title: "Angular Scheduler Dynamic View Switching Example | Mobiscroll"
component: "Scheduler"
framework: "Angular"
library_version: "6.2.0"
url: "https://demo.mobiscroll.com/angular/scheduler/switching-calendar-scheduler-agenda"
---

# Dynamic View Switching - Angular Scheduler demo

Switch between year, month, week, day, and agenda views in the Angular event calendar — via header control or programmatically.

- [Live demo](https://demo.mobiscroll.com/angular/scheduler/switching-calendar-scheduler-agenda)
- [View code on GitHub](https://github.com/acidb/mobiscroll-demos-angular/tree/main/src/demos/eventcalendar/scheduler/switching-calendar-scheduler-agenda)
- This demo in other frameworks: [JavaScript](https://demo.mobiscroll.com/scheduler/switching-calendar-scheduler-agenda.md), [jQuery](https://demo.mobiscroll.com/jquery/scheduler/switching-calendar-scheduler-agenda.md), [React](https://demo.mobiscroll.com/react/scheduler/switching-calendar-scheduler-agenda.md), [Vue](https://demo.mobiscroll.com/vue/scheduler/switching-calendar-scheduler-agenda.md)

## Description

Dynamically switch views within one instance. Use a UI control to let users do the switching or do it programmatically.

The example features a month view with events as labels, a weekly schedule view, a daily schedule and a weekly agenda. Use property binding and when the value of the property changes the settings propagate.

## What this demo shows

- A desktop event calendar with a header segmented control for switching between year, month, week, day, and agenda views.
- **Header and segmented control** A segemnted control with `Year`, `Month`, `Week`, `Day` and `Agenda` options is positioned in the center of the header, between the year navigation label (quick navigation picker) on the left and the blue prev/next arrows with a `Today` button on the right.
- **Month view** The demo opens with the `Month` option selected and displays a desktop month view with event labels.
- **Event labels** Days with events show labels directly inside the month cells, with different colors and styles for all-day, multi-day, and timed events.
- **Overflow handling** When a day cell cannot show all events, additional events are collapsed into an `X more` label. Clicking the label opens a popover with the remaining events for that day.
- **Label interaction** Hovering or clicking an event label selects it and highlights the selected label.
- **Day cell states** Hovering an empty day cell highlights the day number with a gray background. Clicking the empty part of a cell selects the day and highlights the day number with a blue background.
- **Year view** Selecting `Year` shows all twelve months of the current year in a single scrollable layout.
- **Year view events** Days with events show a small label below the date. When multiple events are scheduled, an `X more` label opens a popover above the day cell with the events for that date.
- **Week view** Selecting `Week` shows a desktop weekly scheduler layout with a fixed week strip, a fixed all-day row, and a scrollable time grid for the selected week.
- **Week strip** The strip below the header shows the days of the selected week, with the current date highlighted by a blue circle.
- **Week events** Timed events appear in the scheduler grid as colored cards with a left color stripe, bold event title, and exact start and end time above the title.
- **Current time** A blue current-time line appears across the week time grid, with a small blue dot marking the current date.
- **Time indicator** Hovering over the week time grid shows a time indicator that follows the cursor in 15-minute increments.
- **Day view** Selecting `Day` shows a desktop daily scheduler layout with a fixed week strip, a fixed all-day row, and a scrollable time grid for the selected day.
- **Day navigation** The week strip shows surrounding dates for quick day switching. Dates highlight on hover, and the selected day is marked with a blue circle.
- **Day events** Timed events appear in the daily scheduler grid as colored cards with a left color stripe, bold event title, and exact start and end time above the title.
- **Day current time** A blue current-time line appears across the daily time grid.
- **Day time indicator** Hovering over the daily time grid shows a time indicator that follows the cursor in 15-minute increments.
- **Agenda view** Selecting `Agenda` shows a week calendar at the top and a daily agenda list below it.
- **Agenda selection** The agenda list displays events for the selected date. Selecting a different date in the week calendar updates the agenda automatically.
- **Agenda event markers** Days with events display a small marker below the day in the week calendar.
- **Event creation** Double-clicking or clicking and dragging in the event calendar or scheduler creates a new event.

## Best for

- **Multi-level schedule browsing** Apps where users need to move between year, month, week, day, and agenda views without leaving the same calendar instance.
- **Operational planning** Workflows that need both a broad overview of upcoming activity and detailed time-grid planning for a selected week or day.
- **Daily event review** Interfaces where users need to select a date and review that day's events in an agenda list.
- **Dense calendars** Schedules where month and year views need to handle days with more events than can fit visibly in the cell.
- **Interactive scheduling** Use cases where users create events directly from the calendar or scheduler grid.

## API used in this demo

- [`theme`](https://mobiscroll.com/docs/angular/eventcalendar/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/angular/eventcalendar/api#opt-themeVariant) - option
- [`view`](https://mobiscroll.com/docs/angular/eventcalendar/api#opt-view) - option
- [`labels`](https://mobiscroll.com/docs/angular/eventcalendar/api#opt-labels) - option
- [`data`](https://mobiscroll.com/docs/angular/eventcalendar/api#opt-data) - option
- [`headerTemplate`](https://mobiscroll.com/docs/angular/eventcalendar/api#template-headerTemplate) - template

## Code

### Component

```ts
import { CommonModule } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MbscCalendarEvent, MbscEventcalendarView, MbscModule, setOptions } from '@mobiscroll/angular';

setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

@Component({
  selector: 'app-root', 
  templateUrl: './app.component.html',
  standalone: true,
  imports: [CommonModule, FormsModule, MbscModule],
})
export class AppComponent implements OnInit {
  constructor(private http: HttpClient) {}

  myEvents: MbscCalendarEvent[] = [];
  view = 'month';
  calView: MbscEventcalendarView = {
    calendar: { labels: true },
  };

  ngOnInit(): void {
    this.http.jsonp<MbscCalendarEvent[]>('https://trial.mobiscroll.com/events/?vers=5', 'callback').subscribe((resp) => {
      this.myEvents = resp;
    });
  }

  changeView(): void {
    setTimeout(() => {
      switch (this.view) {
        case 'year':
          this.calView = {
            calendar: { type: 'year' },
          };
          break;
        case 'month':
          this.calView = {
            calendar: { labels: true },
          };
          break;
        case 'week':
          this.calView = {
            scheduler: { type: 'week' },
          };
          break;
        case 'day':
          this.calView = {
            scheduler: { type: 'day' },
          };
          break;
        case 'agenda':
          this.calView = {
            calendar: { type: 'week' },
            agenda: { type: 'week' },
          };
          break;
      }
    });
  }
}
```

### Template

```html
<div class="md-switching-view-cont">
  <mbsc-eventcalendar [data]="myEvents" [view]="calView" [headerTemplate]="customTemplate">
    <ng-template #customTemplate>
      <mbsc-calendar-nav class="cal-header-nav"></mbsc-calendar-nav>
      <div class="cal-header-picker">
        <mbsc-segmented-group [(ngModel)]="view" (change)="changeView()">
          <mbsc-segmented value="month">Month</mbsc-segmented>
          <mbsc-segmented value="week">Week</mbsc-segmented>
          <mbsc-segmented value="day">Day</mbsc-segmented>
          <mbsc-segmented value="agenda">Agenda</mbsc-segmented>
        </mbsc-segmented-group>
      </div>
      <mbsc-calendar-prev class="cal-header-prev"></mbsc-calendar-prev>
      <mbsc-calendar-today class="cal-header-today"></mbsc-calendar-today>
      <mbsc-calendar-next class="cal-header-next"></mbsc-calendar-next>
    </ng-template>
  </mbsc-eventcalendar>
</div>
```

### CSS

```css
.md-switching-view-cont .mbsc-segmented {
  max-width: 350px;
  margin: 0 auto;
}

.md-switching-view-cont .mbsc-calendar-grid-item {
  height: 490px;
  box-sizing: border-box;
}

.cal-header-picker {
  flex: 1 0 auto;
}

.cal-header-nav {
  width: 200px;
}

/* material header order */

.mbsc-material.cal-header-prev {
  order: 1;
}

.mbsc-material.cal-header-next {
  order: 2;
}

.mbsc-material.cal-header-nav {
  order: 3;
}

.mbsc-material .cal-header-picker {
  order: 4;
}

.mbsc-material .cal-header-today {
  order: 5;
}

/* windows header order */

.mbsc-windows.cal-header-nav {
  order: 1;
}

.mbsc-windows.cal-header-prev {
  order: 2;
}

.mbsc-windows.cal-header-next {
  order: 3;
}

.mbsc-windows .cal-header-picker {
  order: 4;
}

.mbsc-windows .cal-header-today {
  order: 5;
}
```

## Implementation notes

- Define five view configurations to switch between:
  - **Year**: `{ calendar: { type: 'year' } }`
  - **Month**: `{ calendar: { labels: true } }` (initial view)
  - **Week**: `{ scheduler: { type: 'week' } }`
  - **Day**: `{ scheduler: { type: 'day' } }`
  - **Agenda**: `{ calendar: { type: 'week' }, agenda: { type: 'week' } }`
- Use `renderHeader` (Angular: `headerTemplate`, Vue: `#header` slot) to render a `SegmentedGroup` in the custom header with one option per view. On selection, update the active view; for the imperative API, call `inst.setOptions({ view: newViewConfig })`.
- Load events from `https://trial.mobiscroll.com/events/?vers=5` via JSONP using `getJson(url, callback, 'jsonp')`. For the imperative API, call `inst.setEvents(events)` in the callback.

## Run it in your project

1. If not signed up yet, or don't own a license, you can [start a free trial](https://mobiscroll.com/starttrial).

2. Clone the repository:

   ```
   git clone https://github.com/acidb/mobiscroll-demos-angular.git
   ```

3. If not installed yet, install the Mobiscroll CLI from NPM:

   ```
   npm install -g @mobiscroll/cli
   ```

4. Config Mobiscroll - open a terminal window in the root directory and run:

   ```
   mobiscroll config angular
   ```

5. Install dependencies - open a terminal window in the root directory and run:

   ```
   npm install
   ```

6. Run the project:

   ```
   ng serve
   ```

On a trial, add `--trial` to the config command: `mobiscroll config angular --trial`.

Running a demo locally requires a Mobiscroll trial or a license; setup is per framework at https://mobiscroll.com/docs/angular/getting-started/installation

## Related demos

- Previous: [Color-Coded Time Blocks](https://demo.mobiscroll.com/angular/scheduler/colored-cell-background.md) - Color Angular Scheduler cell backgrounds for time ranges — mark lunch breaks, maintenance windows, or recurring schedules.
- Next: [Visible hours and days](https://demo.mobiscroll.com/angular/scheduler/show-hide-hours-days.md) - Keep your calendar focused. Trim your view. In Angular, you can show only weekdays and business hours, making schedules cleaner and faster.
