Google Calendar Sync
Usage
theme: 'ios' You can turn auto theming on and let it decide based on the platform.
Usage
themeVariant: 'light' You can turn auto dark mode on based on system settings.
Usage
clickToCreate: true,
// click to create is on dragToCreate: true,
// drag to create is on dragToMove: true,
// reordering is on dragToResize: true,
// resizing is on eventDelete: true
// deleting is on Fine-tune drag & drop with these options, which are false by default.
Usage
locale: localeEn Selecting the locale loads the localized settings and the translated UI text.
Google Calendar Sync
The event calendar comes with third party calendar integration support through the integration plugin. This needs to be added to the download package or installed separately from a dedicated NPM package.
It includes everything you need to authenticate your users, get their Google calendars and provides functions for CRUD operations. It takes care of loading the events and converts them to the required format so that they can be displayed on the Mobiscroll calendar separately or mixed with other calendars and events.
Customizing the interaction, event workflows, whether the events are read-only is up to you. In this live demo, newly created events will land in the primary calendar of the authenticated user.
Demo
The live demo didn't load.
Try it on demo.mobiscroll.comLog into your Google account to view and edit your Google Calendar events
Editing events sync back to your calendar when enabled. You'll be asked for confirmation on every action.

Code
import { CommonModule } from '@angular/common';
import { Component, NgZone, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MbscCalendarEvent, MbscEventcalendarOptions, MbscModule, Notifications, setOptions } from '@mobiscroll/angular';
import { googleCalendarSync } from '@mobiscroll/calendar-integration';
setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
});
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
providers: [Notifications],
standalone: true,
imports: [CommonModule, FormsModule, MbscModule],
})
export class AppComponent implements OnInit {
constructor(
public notify: Notifications,
public zone: NgZone,
) {}
myEvents: MbscCalendarEvent[] = [];
isEditable = false;
isLoggedIn = false;
isLoading = false;
isHidden = true;
calendarIds: string[] = [];
myCalendars: any = [];
startDate!: Date;
endDate!: Date;
debounce: any;
calendarData: any = {};
primaryCalendarId!: string;
calendarOptions: MbscEventcalendarOptions = {
view: {
calendar: { labels: true },
},
extendDefaultEvent: () => ({
color: this.calendarData[this.primaryCalendarId].color,
}),
onPageLoading: (args: any) => {
this.startDate = args.viewStart;
this.endDate = args.viewEnd;
clearTimeout(this.debounce);
this.debounce = setTimeout(() => {
if (googleCalendarSync.isSignedIn()) {
this.isLoading = true;
googleCalendarSync
.getEvents(this.calendarIds, this.startDate, this.endDate)
.then((resp: any) => {
this.zone.run(() => {
this.myEvents = resp;
this.isLoading = false;
});
})
.catch((error: any) => {
this.onError(error);
});
}
}, 200);
},
onEventCreate: (args: any) => {
if (googleCalendarSync.isSignedIn()) {
const event = args.event;
googleCalendarSync
.addEvent(this.primaryCalendarId, event)
.then((resp: any) => {
this.zone.run(() => {
resp.color = event.color;
this.myEvents = [...this.myEvents.filter((item) => item.id !== event.id), resp];
});
this.notify.toast({
message: 'Event created in "' + this.calendarData[this.primaryCalendarId].name + '" calendar',
});
})
.catch((error: any) => {
this.zone.run(() => {
this.myEvents = this.myEvents.filter((item) => item.id !== event.id);
this.onError(error);
});
});
}
},
onEventUpdate: (args) => {
if (googleCalendarSync.isSignedIn()) {
this.notify
.confirm({
title: 'Are you sure you want to update this event?',
message: 'This action will affect your Google Calendar event.',
okText: 'Update',
})
.then((result) => {
const event = args.event;
if (result) {
const calendarId = event['googleCalendarId'];
googleCalendarSync
.updateEvent(calendarId, event)
.then(() => {
this.notify.toast({
message: 'Event updated on "' + this.calendarData[calendarId].name + '" calendar',
});
})
.catch(() => {
this.zone.run(() => {
this.myEvents = [...this.myEvents.filter((item) => item.id !== event.id), args.oldEvent!];
});
});
} else {
this.myEvents = [...this.myEvents.filter((item) => item.id !== event.id), args.oldEvent!];
}
});
}
},
onEventDelete: (args) => {
if (googleCalendarSync.isSignedIn()) {
this.notify
.confirm({
title: 'Are you sure you want to delete this event?',
message: 'This action will remove the event from your Google Calendar as well.',
okText: 'Delete',
})
.then((result) => {
if (result) {
const event = args.event;
const calendarId = event['googleCalendarId'];
googleCalendarSync
.deleteEvent(calendarId, event)
.then(() => {
this.zone.run(() => {
this.myEvents = this.myEvents.filter((item) => item.id !== event.id);
});
this.notify.toast({
message: 'Event deleted from "' + this.calendarData[calendarId].name + '" calendar',
});
})
.catch((error: any) => {
this.onError(error);
});
}
});
}
return false;
},
};
ngOnInit(): void {
this.isHidden = false;
googleCalendarSync.init({
apiKey: '<YOUR_GOOGLE_API_KEY>',
clientId: '<YOUR_GOOGLE_CLIENT_ID>',
onSignedIn: () => {
this.isLoggedIn = true;
googleCalendarSync
.getCalendars()
.then((calendars: any) => {
calendars.sort((a: { primary: boolean }) => (a.primary ? -1 : 1));
this.myCalendars = calendars;
this.primaryCalendarId = calendars[0].id;
this.calendarIds = [...this.calendarIds, this.primaryCalendarId];
for (const c of calendars) {
this.calendarData[c.id] = { name: c.summary, color: c.backgroundColor, checked: false };
}
this.isLoading = true;
googleCalendarSync
.getEvents([this.primaryCalendarId], this.startDate, this.endDate)
.then((resp: any) => {
this.zone.run(() => {
this.myEvents = resp;
this.calendarData[this.primaryCalendarId].checked = true;
this.isLoading = false;
});
})
.catch((error: any) => {
this.onError(error);
});
})
.catch((error: any) => {
this.onError(error);
});
},
onSignedOut: () => {
this.isLoggedIn = false;
this.myCalendars = [];
this.calendarIds = [];
this.calendarData = {};
this.myEvents = [];
},
});
}
onError(resp: any): void {
this.notify.toast({
message: resp.error ? resp.error : resp.result.error.message,
});
}
changeEditable(ev: any): void {
this.isEditable = ev.target.checked;
}
toggleCalendars(ev: any, calendarId: string): void {
const checked = ev.target.checked;
this.calendarData[calendarId].checked = checked;
if (checked) {
this.calendarIds = [...this.calendarIds, calendarId];
} else {
this.calendarIds = this.calendarIds.filter((id) => id !== calendarId);
}
if (this.calendarIds.length === 0) {
this.myEvents = [];
return;
}
this.isLoading = true;
googleCalendarSync
.getEvents(this.calendarIds, this.startDate, this.endDate)
.then((resp: any) => {
this.zone.run(() => {
this.myEvents = resp;
this.isLoading = false;
});
})
.catch((error: any) => {
this.onError(error);
});
}
logOut(): void {
googleCalendarSync.signOut().catch((error: any) => {
this.onError(error);
});
}
logIn(): void {
if (!googleCalendarSync.isSignedIn()) {
googleCalendarSync.signIn().catch((error: any) => {
this.onError(error);
});
}
}
}
<mbsc-page class="md-sync-events-google-cont" [ngClass]="{'md-loading-events': isLoading}">
<div [ngClass]="{'md-sync-events-google-menu': true, 'mbsc-hidden': isHidden}">
<ng-container *ngIf="!isLoggedIn">
<div class="mbsc-form-group-inset mbsc-align-center" [attr.aria-hidden]="isLoggedIn">
<p class="mbsc-italic mbsc-txt-muted">Log into your Google account to view and edit your Google Calendar events</p>
<button (click)="logIn()" class="mbsc-reset md-sync-events-google-button">Sign in with Google</button>
</div>
</ng-container>
<ng-container *ngIf="isLoggedIn">
<div [attr.aria-hidden]="!isLoggedIn">
<div class="mbsc-form-group-inset mbsc-align-center">
<p class="mbsc-italic mbsc-txt-muted">
Editing events sync back to your calendar when enabled. You'll be asked for confirmation on every action.
</p>
</div>
<div class="mbsc-form-group-inset">
<mbsc-switch label="Enable editing" [(ngModel)]="isEditable" (change)="changeEditable($event)"></mbsc-switch>
</div>
<div class="mbsc-form-group-inset md-sync-events-google-inset">
<ng-container *ngFor="let cal of myCalendars;">
<mbsc-switch
label="{{cal.summary}}"
[(ngModel)]="calendarData[cal.id].checked"
(change)="toggleCalendars($event, cal.id)"
></mbsc-switch>
</ng-container>
</div>
<div class="mbsc-form-group-inset">
<mbsc-button class="mbsc-button-block" (click)="logOut()">Log out of my account </mbsc-button>
</div>
</div>
</ng-container>
</div>
<div class="md-sync-events-google-calendar" [ngClass]="{'md-loading-events': isLoading}">
<div class="md-sync-events-overlay"></div>
<mbsc-eventcalendar
[options]="calendarOptions"
[data]="myEvents"
[exclusiveEndDates]="true"
[clickToCreate]="isEditable"
[dragToCreate]="isEditable"
[dragToMove]="isEditable"
[dragToResize]="isEditable"
[headerTemplate]="customTemplate"
>
<ng-template #customTemplate>
<mbsc-calendar-nav></mbsc-calendar-nav>
<div class="md-spinner">
<div class="md-spinner-blade"></div>
<div class="md-spinner-blade"></div>
<div class="md-spinner-blade"></div>
<div class="md-spinner-blade"></div>
<div class="md-spinner-blade"></div>
<div class="md-spinner-blade"></div>
<div class="md-spinner-blade"></div>
<div class="md-spinner-blade"></div>
<div class="md-spinner-blade"></div>
<div class="md-spinner-blade"></div>
<div class="md-spinner-blade"></div>
<div class="md-spinner-blade"></div>
</div>
<div class="md-google-calendar-header">
<mbsc-calendar-prev></mbsc-calendar-prev>
<mbsc-calendar-today></mbsc-calendar-today>
<mbsc-calendar-next></mbsc-calendar-next>
</div>
</ng-template>
</mbsc-eventcalendar>
</div>
</mbsc-page>
.md-sync-events-google-cont.mbsc-page {
display: flex;
height: 600px;
}
.md-sync-events-google-menu {
flex: 0 0 350px;
height: 100%;
overflow: auto;
}
.md-sync-events-google-calendar {
flex: 1 1 auto;
border-left: 1px solid #ccc;
}
.md-google-calendar-header {
flex: 1 0 auto;
display: flex;
justify-content: flex-end;
}
button.md-sync-events-google-button {
padding: 8px 24px 8px 50px;
line-height: 24px;
background: url(https://cdn.cdnlogo.com/logos/g/35/google-icon.svg) no-repeat;
background-size: 18px 18px;
background-position: 11px 11px;
background-color: #fff;
color: #757575;
font-family: Roboto, arial, sans-serif;
font-size: 13px;
font-weight: 500;
cursor: pointer;
border-radius: 2px;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.25);
transition:
background-color 0.218s,
border-color 0.218s,
box-shadow 0.218s;
}
.md-sync-events-google-button:active {
background-color: #eee;
color: #6d6d6d;
}
.md-sync-events-google-button:hover,
.md-sync-events-google-button:focus {
box-shadow: 0 0 3px 3px rgb(66, 133, 244, 0.3);
}
.md-sync-events-google-inset {
margin-bottom: 0;
}
@media (max-width: 800px) {
.md-sync-events-google-cont.mbsc-page {
display: block;
height: auto;
}
}
/* loading spinner and overlay */
.md-loading-events .md-sync-events-overlay {
position: absolute;
z-index: 2;
top: 0;
right: 0;
bottom: 0;
left: 0;
-webkit-transform: translateZ(0);
transform: translateZ(0);
}
.md-spinner {
visibility: hidden;
position: relative;
width: 20px;
height: 20px;
}
.md-loading-events .md-spinner {
visibility: visible;
}
.md-spinner .md-spinner-blade {
position: absolute;
left: 44.5%;
top: 37%;
width: 10%;
height: 25%;
border-radius: 50%/20%;
background-color: #8c8c8c;
-webkit-animation: md-spinner-fade 1s linear infinite;
animation: md-spinner-fade 1s linear infinite;
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
.md-spinner .md-spinner-blade:nth-child(1) {
-webkit-animation-delay: -1.66667s;
animation-delay: -1.66667s;
-webkit-transform: rotate(30deg) translate(0, -150%);
transform: rotate(30deg) translate(0, -150%);
}
.md-spinner .md-spinner-blade:nth-child(2) {
-webkit-animation-delay: -1.58333s;
animation-delay: -1.58333s;
-webkit-transform: rotate(60deg) translate(0, -150%);
transform: rotate(60deg) translate(0, -150%);
}
.md-spinner .md-spinner-blade:nth-child(3) {
-webkit-animation-delay: -1.5s;
animation-delay: -1.5s;
-webkit-transform: rotate(90deg) translate(0, -150%);
transform: rotate(90deg) translate(0, -150%);
}
.md-spinner .md-spinner-blade:nth-child(4) {
-webkit-animation-delay: -1.41667s;
animation-delay: -1.41667s;
-webkit-transform: rotate(120deg) translate(0, -150%);
transform: rotate(120deg) translate(0, -150%);
}
.md-spinner .md-spinner-blade:nth-child(5) {
-webkit-animation-delay: -1.33333s;
animation-delay: -1.33333s;
-webkit-transform: rotate(150deg) translate(0, -150%);
transform: rotate(150deg) translate(0, -150%);
}
.md-spinner .md-spinner-blade:nth-child(6) {
-webkit-animation-delay: -1.25s;
animation-delay: -1.25s;
-webkit-transform: rotate(180deg) translate(0, -150%);
transform: rotate(180deg) translate(0, -150%);
}
.md-spinner .md-spinner-blade:nth-child(7) {
-webkit-animation-delay: -1.16667s;
animation-delay: -1.16667s;
-webkit-transform: rotate(210deg) translate(0, -150%);
transform: rotate(210deg) translate(0, -150%);
}
.md-spinner .md-spinner-blade:nth-child(8) {
-webkit-animation-delay: -1.08333s;
animation-delay: -1.08333s;
-webkit-transform: rotate(240deg) translate(0, -150%);
transform: rotate(240deg) translate(0, -150%);
}
.md-spinner .md-spinner-blade:nth-child(9) {
-webkit-animation-delay: -1s;
animation-delay: -1s;
-webkit-transform: rotate(270deg) translate(0, -150%);
transform: rotate(270deg) translate(0, -150%);
}
.md-spinner .md-spinner-blade:nth-child(10) {
-webkit-animation-delay: -0.91667s;
animation-delay: -0.91667s;
-webkit-transform: rotate(300deg) translate(0, -150%);
transform: rotate(300deg) translate(0, -150%);
}
.md-spinner .md-spinner-blade:nth-child(11) {
-webkit-animation-delay: -0.83333s;
animation-delay: -0.83333s;
-webkit-transform: rotate(330deg) translate(0, -150%);
transform: rotate(330deg) translate(0, -150%);
}
.md-spinner .md-spinner-blade:nth-child(12) {
-webkit-animation-delay: -0.75s;
animation-delay: -0.75s;
-webkit-transform: rotate(360deg) translate(0, -150%);
transform: rotate(360deg) translate(0, -150%);
}
.md-loading-events .md-spinner-blade {
-webkit-animation-play-state: running;
animation-play-state: running;
}
@-webkit-keyframes md-spinner-fade {
0% {
opacity: 0.85;
}
50% {
opacity: 0.25;
}
100% {
opacity: 0.25;
}
}
@keyframes md-spinner-fade {
0% {
opacity: 0.85;
}
50% {
opacity: 0.25;
}
100% {
opacity: 0.25;
}
}