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, the different calendars are handled as resources and have their own timeline rows. You can manipulate events in the desired calendars, while read-only calendars are greyed out.
Demo
The live demo didn't load.
Try it on demo.mobiscroll.comEditing 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, ElementRef, NgZone, OnInit, ViewChild } from '@angular/core';
import { FormsModule } from '@angular/forms';
import {
MbscCalendarEvent,
MbscEventcalendarOptions,
MbscModule,
MbscPopup,
MbscPopupOptions,
MbscResource,
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,
) {}
@ViewChild('popup', { static: false }) popup!: MbscPopup;
@ViewChild('calButton') anchorElm!: ElementRef;
myEvents: MbscCalendarEvent[] = [];
isEditable = false;
isLoggedIn = false;
isLoading = false;
calendarIds: string[] = [];
myCalendars: any = [];
readonlyCalendars: string[] = [];
startDate!: Date;
endDate!: Date;
debounce: any;
calendarData: any = {};
myResources: MbscResource[] = [];
myInvalids: any[] = [];
myAnchor: any;
selectedDate: any = new Date();
calendarOptions: MbscEventcalendarOptions = {
view: {
timeline: {
type: 'week',
eventDisplay: 'fill',
},
},
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(() => {
resp.forEach((event: any) => {
event.resource = event.googleCalendarId;
});
this.myEvents = resp;
this.isLoading = false;
});
})
.catch((error: any) => {
this.onError(error);
});
}
}, 200);
},
onEventCreate: (args: any) => {
if (googleCalendarSync.isSignedIn()) {
const event = args.event;
const calendarId = event.resource;
if (this.readonlyCalendars.indexOf(calendarId) !== -1) {
this.notify.toast({
message: 'This calendar is readonly',
});
} else {
googleCalendarSync
.addEvent(calendarId, event)
.then((resp: any) => {
this.zone.run(() => {
resp.resource = event.resource;
this.myEvents = [...this.myEvents.filter((item) => item.id !== event.id), resp];
});
this.notify.toast({
message: 'Event created in "' + this.calendarData[calendarId].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;
},
};
popupOptions: MbscPopupOptions = {
width: 400,
touchUi: false,
showOverlay: false,
scrollLock: false,
contentPadding: false,
display: 'anchored',
};
ngOnInit(): void {
googleCalendarSync.init({
apiKey: '<YOUR_GOOGLE_API_KEY>',
clientId: '<YOUR_GOOGLE_CLIENT_ID>',
onSignedIn: () => {
this.isLoggedIn = true;
googleCalendarSync
.getCalendars()
.then((calendars: any) => {
const newCalendarIds = [];
const newResources = [];
const readonlyCals = [];
calendars.sort((a: { isDefaultCalendar: boolean }) => (a.isDefaultCalendar ? -1 : 1));
for (const c of calendars) {
newCalendarIds.push(c.id);
newResources.push({ id: c.id, name: c.summary, color: c.hexColor });
this.calendarData[c.id] = { name: c.summary, color: c.hexColor, checked: true };
if (!(c.accessRole === 'writer' || c.accessRole === 'owner')) {
readonlyCals.push(c.id);
}
}
this.myCalendars = calendars;
this.calendarIds = newCalendarIds;
this.myResources = newResources;
this.readonlyCalendars = readonlyCals;
this.isLoading = true;
this.myInvalids = [
{
recurring: {
repeat: 'daily',
},
resource: readonlyCals,
},
];
googleCalendarSync
.getEvents(this.calendarIds, this.startDate, this.endDate)
.then((resp: any) => {
this.zone.run(() => {
resp.forEach((event: any) => {
event.resource = event.googleCalendarId;
});
this.myEvents = resp;
this.isLoading = false;
});
})
.catch((error: any) => {
this.onError(error);
});
})
.catch((error: any) => {
this.onError(error);
});
},
onSignedOut: () => {
this.isLoggedIn = false;
this.popup.close();
this.myCalendars = [];
this.calendarIds = [];
this.calendarData = {};
this.myEvents = [];
this.myResources = [];
this.myInvalids = [];
this.readonlyCalendars = [];
},
});
}
onError(error: any): void {
this.notify.toast({
message: error || 'An error occured',
});
}
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) {
const newResource = this.calendarData[calendarId];
this.myResources = [...this.myResources, { id: calendarId, name: newResource.name, color: newResource.color }];
this.calendarIds = [...this.calendarIds, calendarId];
} else {
this.myResources = this.myResources.filter((r) => r.id !== calendarId);
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(() => {
resp.forEach((event: any) => {
event.resource = event.googleCalendarId;
});
this.myEvents = resp;
this.isLoading = false;
});
})
.catch((error: any) => {
this.onError(error);
});
}
openPopup(): void {
this.myAnchor = this.anchorElm.nativeElement;
this.popup.open();
}
navigate(): void {
this.selectedDate = new Date();
}
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}">
<mbsc-eventcalendar
[options]="calendarOptions"
[data]="myEvents"
[resources]="myResources"
[invalid]="myInvalids"
[exclusiveEndDates]="true"
[clickToCreate]="isEditable"
[dragToCreate]="isEditable"
[dragToMove]="isEditable"
[dragToResize]="isEditable"
[headerTemplate]="customTemplate"
[(selectedDate)]="selectedDate"
>
<ng-template #customTemplate>
<mbsc-calendar-nav class="md-sync-events-google-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-buttons">
<mbsc-button (click)="logIn()" *ngIf="!isLoggedIn" class="md-sync-events-google-button">Sync my google calendars </mbsc-button>
<mbsc-button #calButton (click)="openPopup()" *ngIf="isLoggedIn" class="md-sync-events-google-button">My Calendars </mbsc-button>
<mbsc-button (click)="navigate()">Today</mbsc-button>
<mbsc-calendar-prev></mbsc-calendar-prev>
<mbsc-calendar-next></mbsc-calendar-next>
</div>
</ng-template>
</mbsc-eventcalendar>
<mbsc-popup [options]="popupOptions" [anchor]="myAnchor" #popup>
<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">
<div class="mbsc-form-group-title">My calendars</div>
<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="md-sync-events-google-button mbsc-button-block" (click)="logOut()">Log out of my account </mbsc-button>
</div>
</mbsc-popup></mbsc-page
>
.md-google-calendar-buttons {
flex: 1 0 auto;
display: flex;
justify-content: flex-end;
margin-right: 10px;
}
.md-sync-events-google-calendar {
border-left: 1px solid #ccc;
}
.md-google-calendar-header {
flex: 1 0 auto;
display: flex;
justify-content: flex-end;
}
.md-sync-events-google-nav {
justify-content: flex-start;
}
.md-sync-events-google-button.mbsc-button {
text-transform: capitalize;
}
.md-sync-events-google-inset {
margin-bottom: 0;
}
/* 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;
}
}