Load Public Google Calendar Events

Event data can be loaded from remote sources, like public google calendars. Through the integration plugin you can easily show events that are available in a public calendar. The integration plugin needs to be added to the download package or installed separately from a dedicated NPM package.

You will just need the CALENDAR_ID and an apiKey from google and you should be ready to roll.

Public calendars are read-only. If you are interested in syncing private google calendars with read/write/delete access, check out this example.

This example uses the integration plugin to connect to and load events from Google Calendar and it is not available in the trial. Give the live demo a try and see how it can be configured.
Get started with the agenda

Demo

Loading the live demo

Preview in full screen

Load events from a public Google Calendar into the agenda view using the integration plugin — connect with a Calendar ID and API key.

Code

import { CommonModule } from '@angular/common';
import { Component, NgZone, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import {
  MbscCalendarEvent,
  MbscEventcalendarView,
  MbscModule,
  MbscPageLoadingEvent,
  Notifications,
  setOptions ,
} from '@mobiscroll/angular';
import { googleCalendarSync } from '@mobiscroll/calendar-integration';

setOptions({
  locale:  ,
  theme: ' ',
  themeVariant: ' '
});

const CALENDAR_ID = 'theacidmedia.net_8l6v679q5j2f7q8lpmcjr4mm3k@group.calendar.google.com';

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

  currentView = 'agenda';
  firstDay!: Date;
  lastDay!: Date;
  isLoading = false;
  myEvents: MbscCalendarEvent[] = [];
  myView: MbscEventcalendarView = {
    calendar: { type: 'week' },
    agenda: { type: 'week' },
  };

  onPageLoading(event: MbscPageLoadingEvent): void {
    const start = event.viewStart;
    const end = event.viewEnd;

    // Calculate dates
    // (pre-load events for previous and next pages as well)
    if (this.currentView === 'month') {
      this.firstDay = start;
      this.lastDay = end;
    } else {
      this.firstDay = new Date(start.getFullYear(), start.getMonth(), start.getDate() - 7);
      this.lastDay = new Date(end.getFullYear(), end.getMonth(), end.getDate() + 7);
    }
    this.loadEvents();
  }

  onError(resp: { error?: string; result: { error: { message: string } } }): void {
    this.notify.toast({
      message: resp.error ? resp.error : resp.result.error.message,
    });
  }

  loadEvents(): void {
    this.isLoading = true;
    googleCalendarSync
      .getEvents(CALENDAR_ID, this.firstDay, this.lastDay)
      .then((resp) => {
        this.zone.run(() => {
          this.myEvents = resp;
          this.isLoading = false;
        });
      })
      .catch((error) => {
        this.onError(error);
      });
  }

  changeView(): void {
    setTimeout(() => {
      switch (this.currentView) {
        case 'month':
          this.myView = { calendar: { labels: true } };
          break;
        case 'week':
          this.myView = { scheduler: { type: 'week' } };
          break;
        case 'day':
          this.myView = { scheduler: { type: 'day' } };
          break;
        case 'agenda':
        default:
          this.myView = {
            calendar: { type: 'week' },
            agenda: { type: 'week' },
          };
          break;
      }
    });
  }

  ngOnInit(): void {
    googleCalendarSync.init({
      apiKey: '<YOUR_GOOGLE_API_KEY>',
      onInit: () => {
        this.loadEvents();
      },
    });
  }
}

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.