CRUD
Updating event properties
The Eventcalendar is bound to an array of event objects as described in the data binding section. To update a single event with new event data, it's not enough to update the particular event object. A new event array reference is also needed otherwise the change won't be picked up by the eventcalendar.
Updating an event title
import { Component } from '@angular/core';
import { MbscCalendarEvent, MbscEventcalendarView } from '@mobiscroll/angular';
@Component({...})
export class MyComponent {
myView: MbscEventcalendarView = {
calendar: { type: "month" },
agenda: { type: "month" },
};
myEvents: MbscCalendarEvent[] = [
{ id: 'id1' start: '2023-09-24', end: '2023-09-30', title: 'Short trip!'},
{ id: 'id2' start: '2023-10-12', end: '2023-10-12', title: 'Birthday'},
{ id: 'id3' start: '2023-12-24', end: '2023-12-26', title: 'X-mas'},
];
editEvent(eventID: string) {
const myNewArray = [...this.myEvents];
const index = myNewArray.findIndex((ev) => ev.id === eventID);
myNewArray[index].title = 'My Birthday';
this.myEvents = myNewArray;
}
}
<mbsc-eventcalendar [data]="myEvents" [view]="myView"></mbsc-eventcalendar>
<mbsc-button (click)="editEvent('id2')">Edit second event</mbsc-button>
The same concept can be used to add or delete a calendar event. Or to update any properties of an event with incoming data, regardless where the data comes from (outside of the eventcalendar), be it an edit form or an external API.