---
title: "Angular Timeline Day/Week View Switcher Example | Mobiscroll"
component: "Timeline"
framework: "Angular"
library_version: "6.2.0"
url: "https://demo.mobiscroll.com/angular/timeline/switching-day-week-work-week-timeline"
---

# Day/Week View Switcher - Angular Timeline demo

Build resource schedules with day, work-week, and full-week views on a Angular Timeline — switch views from the header to control time-grid detail.

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

## Description

Scheduling people, teams or an entire workforce requires different views. Sometimes you'll be needing a helicopter view of a week and other times you might want to dig into a specific day. This all can be served through a simple switching mechanism implemented with a segmented control right in the header of the calendar.

By [dynamically changing the options](https://mobiscroll.com/docs/angular/eventcalendar/api) you can set the level of detail you want to see. *Eg. Show a daily timeline with hourly steps, show the work week with the same resolution or zoom out for a full week-view with 12 hour steps.*

**Want to see how to set other views?** [Check out this example for switching views →](https://demo.mobiscroll.com/angular/scheduler/switching-calendar-scheduler-agenda)

## What this demo shows

- A desktop scheduler timeline with days arranged horizontally and resources listed as rows on the left.
- **Header navigation** The month and year label opens date navigation, the previous and next buttons move between weeks, and the Today button returns to the current date.
- **View switcher** The header includes Day, Work week, and Week options, with Week selected by default.
- **Day view** Selecting Day updates the timeline to a single-day timeline view.
- **Work week view** Selecting Work week updates the timeline to show Monday through Friday.
- **Week view** Selecting Week updates the timeline to show a full Sunday-to-Saturday week.
- **Week strip** The strip below the header shows the selected week from Sunday to Saturday, with the current date highlighted.
- **Time grid** The timeline displays hourly columns across the visible day range.
- **Invalid time ranges** Early-morning and late-evening hours are blocked on weekdays, appear with a gray background, and do not allow event creation or event movement.
- **Invalid weekend** Saturdays and Sundays are blocked, so the weekend columns appear with a gray background and do not allow event creation.
- **Resources** Each resource is displayed as a separate timeline row with an avatar, person name, and job title.
- **Current time** A vertical blue line with a time label marks the current time.
- **Hover behavior** Hovering over the time grid shows a time indicator that follows the cursor in 15-minute increments.
- **Event cards** Events are shown as colored cards with a left color stripe, bold title, and time range.
- **Date positioning** Events are positioned by their assigned resource, date, start time, and end time.
- **Event interaction** Events highlight on hover and expose drag and resize handles for moving the event or changing its duration.
- **Event selection** Clicking an event selects and highlights it.
- **Event creation** New events can be created by double-clicking the timeline or by clicking and dragging across a time range.
- **Scrolling** The timeline supports horizontal and vertical scrolling for navigating through time and resources.

## Best for

- **Workforce scheduling** Switching between day, work-week, and full-week views for teams that need both detailed daily planning and broader weekly coverage.
- **Resource planning** Assigning events to people, teams, rooms, equipment, or other resources that need separate rows in a timeline.
- **Shift and availability planning** Blocking non-working hours and weekends so users schedule only inside allowed time ranges.
- **Operational calendars** Reviewing many scheduled items across multiple resources while keeping resource details visible on the left.
- **Staffing dashboards** Showing names, roles, and avatars next to each resource so planners can identify the right person quickly.
- **Drag-and-drop scheduling flows** Creating, moving, and resizing events directly on the timeline while preventing updates in invalid time ranges.

## 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
- [`data`](https://mobiscroll.com/docs/angular/eventcalendar/api#opt-data) - option
- [`resources`](https://mobiscroll.com/docs/angular/eventcalendar/api#opt-resources) - option
- [`invalid`](https://mobiscroll.com/docs/angular/eventcalendar/api#opt-invalid) - option
- [`headerTemplate`](https://mobiscroll.com/docs/angular/eventcalendar/api#template-headerTemplate) - template
- [`resourceTemplate`](https://mobiscroll.com/docs/angular/eventcalendar/api#template-resourceTemplate) - template
- [`onEventCreateFailed`](https://mobiscroll.com/docs/angular/eventcalendar/api#event-onEventCreateFailed) - event
- [`onEventUpdateFailed`](https://mobiscroll.com/docs/angular/eventcalendar/api#event-onEventUpdateFailed) - event

## 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, Notifications, setOptions } from '@mobiscroll/angular';

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

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

  myEvents: MbscCalendarEvent[] = [];
  view = 'week';
  calView: MbscEventcalendarView = {
    timeline: {
      type: 'week',
    },
  };

  myResources = [
    {
      id: 1,
      name: 'Ryan',
      color: '#ff0101',
      title: 'Cloud System Engineer',
      img: 'https://img.mobiscroll.com/demos/m1.png',
    },
    {
      id: 2,
      name: 'Kate',
      color: '#239a21',
      title: 'Help Desk Specialist',
      img: 'https://img.mobiscroll.com/demos/f1.png',
    },
    {
      id: 3,
      name: 'John',
      color: '#8f1ed6',
      title: 'Application Developer',
      img: 'https://img.mobiscroll.com/demos/m2.png',
    },
    {
      id: 4,
      name: 'Mark',
      color: '#01adff',
      title: 'Network Administrator',
      img: 'https://img.mobiscroll.com/demos/m3.png',
    },
    {
      id: 5,
      name: 'Sharon',
      color: '#d8ca1a',
      title: 'Data Quality Manager',
      img: 'https://img.mobiscroll.com/demos/f2.png',
    },
  ];

  myInvalids = [
    {
      start: '00:00',
      end: '06:00',
      recurring: {
        repeat: 'weekly',
        weekDays: 'MO,TU,WE,TH,FR',
      },
    },
    {
      start: '20:00',
      end: '23:59',
      recurring: {
        repeat: 'weekly',
        weekDays: 'MO,TU,WE,TH,FR',
      },
    },
    {
      recurring: {
        repeat: 'weekly',
        weekDays: 'SA,SU',
      },
    },
  ];

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

  changeView(): void {
    setTimeout(() => {
      switch (this.view) {
        case 'day':
          this.calView = {
            timeline: { type: 'day' },
          };
          break;
        case 'workweek':
          this.calView = {
            timeline: {
              type: 'week',
              startDay: 1,
              endDay: 5,
            },
          };
          break;
        case 'week':
          this.calView = {
            timeline: {
              type: 'week',
            },
          };
          break;
      }
    });
  }

  eventUpdateFail(): void {
    this.notify.toast({
      message: "Can't schedule outside of working hours",
    });
  }
}
```

### Template

```html
<div class="md-switching-timeline-view-cont">
  <mbsc-eventcalendar
    [data]="myEvents"
    [view]="calView"
    [resources]="myResources"
    [invalid]="myInvalids"
    [headerTemplate]="myHeaderTemplate"
    [resourceTemplate]="myResourceTemplate"
    (onEventCreateFailed)="eventUpdateFail()"
    (onEventUpdateFailed)="eventUpdateFail()"
  >
    <ng-template #myHeaderTemplate>
      <mbsc-calendar-nav class="md-work-week-nav"></mbsc-calendar-nav>
      <div class="md-work-week-picker">
        <mbsc-segmented-group [(ngModel)]="view" (change)="changeView()">
          <mbsc-segmented value="day">Day</mbsc-segmented>
          <mbsc-segmented value="workweek">Work week</mbsc-segmented>
          <mbsc-segmented value="week">Week</mbsc-segmented>
        </mbsc-segmented-group>
      </div>
      <mbsc-calendar-prev class="md-work-week-prev"></mbsc-calendar-prev>
      <mbsc-calendar-today class="md-work-week-today"></mbsc-calendar-today>
      <mbsc-calendar-next class="md-work-week-next"></mbsc-calendar-next>
    </ng-template>
  </mbsc-eventcalendar>
  <ng-template #myResourceTemplate let-resource>
    <div class="md-work-week-cont">
      <div class="md-work-week-name">{{resource.name}}</div>
      <div class="md-work-week-title">{{resource.title}}</div>
      <img class="md-work-week-avatar" [attr.alt]="resource.name" [src]="resource.img" />
    </div>
  </ng-template>
</div>
```

### CSS

```css
.md-work-week-cont {
  position: relative;
  padding-left: 50px;
}

.md-work-week-avatar {
  position: absolute;
  max-height: 50px;
  max-width: 50px;
  top: 21px;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  left: 20px;
}

.md-work-week-name {
  font-size: 16px;
}

.md-work-week-title {
  font-size: 12px;
  margin-top: 5px;
}

.md-switching-timeline-view-cont .mbsc-segmented {
  max-width: 350px;
  margin: 0 auto;
  padding: 1px;
}

.md-work-week-picker {
  flex: 1 0 auto;
}

.md-work-week-nav {
  width: 200px;
}

.md-switching-timeline-view-cont .mbsc-timeline-resource {
  display: flex;
  align-items: center;
}

.md-switching-timeline-view-cont .mbsc-timeline-resource-col {
  width: 205px;
}

/* material header order */

.mbsc-material.md-work-week-prev {
  order: 1;
}

.mbsc-material.md-work-week-next {
  order: 2;
}

.mbsc-material.md-work-week-nav {
  order: 3;
}

.mbsc-material .md-work-week-picker {
  order: 4;
}

.mbsc-material .md-work-week-today {
  order: 5;
}

/* windows header order */

.mbsc-windows.md-work-week-nav {
  order: 1;
}

.mbsc-windows.md-work-week-prev {
  order: 2;
}

.mbsc-windows.md-work-week-next {
  order: 3;
}

.mbsc-windows .md-work-week-picker {
  order: 4;
}

.mbsc-windows .md-work-week-today {
  order: 5;
}
```

## Implementation notes

- Set `timeline: { type: 'week' }` as the default view. The three switchable views are:
  - **Day**: `timeline: { type: 'day' }`
  - **Work week**: `timeline: { type: 'week', startDay: 1, endDay: 5 }`
  - **Week** (default): `timeline: { type: 'week' }`
- Use `renderHeader` (Angular: `headerTemplate`, Vue: `#header` slot) with the same structure as the event-listing demo: `CalendarNav`, a centered `SegmentedGroup` with three `Segmented` options (`day` / `workweek` / `week`), then `CalendarPrev`, `CalendarToday`, `CalendarNext`. When the selection changes, replace the active view config accordingly.
- Define 5 people resources, each with `id`, `name`, `color`, a `title` (job title string), and an `img` (avatar URL from `https://img.mobiscroll.com/demos/`).
- Use `renderResource` (Angular: `resourceTemplate`, Vue: `#resource` slot) to render a custom resource label showing the person's avatar, name, and job title.
- Define an `invalid` array to block off non-working time on all resources:
  - `{ start: '00:00', end: '06:00', recurring: { repeat: 'weekly', weekDays: 'MO,TU,WE,TH,FR' } }` - early morning
  - `{ start: '20:00', end: '23:59', recurring: { repeat: 'weekly', weekDays: 'MO,TU,WE,TH,FR' } }` - late evening
  - `{ recurring: { repeat: 'weekly', weekDays: 'SA,SU' } }` - full weekend
- Handle `onEventCreateFailed` and `onEventUpdateFailed` by showing a `Toast` with the message "Can't schedule outside of working hours". This fires when drag-to-create or drag-to-move lands in an invalid slot.
- Load events remotely via `getJson` from the trial endpoint.

## 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: [Daily Event Listing](https://demo.mobiscroll.com/angular/timeline/event-listing.md) - Display events as full-day labels across resources on the Angular Timeline — ideal for capacity checks and daily schedule overviews.
- Next: [Data & Display Timezone](https://demo.mobiscroll.com/angular/timeline/setting-the-timezone.md) - Set separate data and display timezones on a Angular Timeline — configure per-resource event timezone display using Luxon, Moment-timezone, or Day.js.
