Hey there every time the eventClick() method will be called, it execute it and then it will route to localhost:4200/null. But my calendar is on route localhost:4200/prime-ng. So i tried to redirect the route '/null' to the calendars route. But the component will be initialized new. Then I found this post: fullcalendar - eventclick changing URL It's actually the same problem as I have, but he did it with JavaScript. So I though I can do the same with the angular router. But it routes just before the URL will be changed.
eventClick: (el) => this.router.navigate(['/prime-ng']),
I would be really thankful if you have some hints and tips for me.
Compnente
import { EventService } from '../services/event.service';
import { EditorState, Lesson } from '../models/calendar-helper';
import { Component, OnInit, ViewChild } from '@angular/core';
import dayGridPlugin from '@fullcalendar/daygrid';
import timeGridPlugin from '@fullcalendar/timegrid';
import interactionPlugin from '@fullcalendar/interaction';
import { FullCalendar } from 'primeng';
import { Router } from '@angular/router';
@Component({
selector: 'app-primeng-calendar',
templateUrl: './primeng-calendar.component.html',
styleUrls: ['./primeng-calendar.component.sass']
})
export class PrimengCalendarComponent implements OnInit {
@ViewChild('calendar', { static: true })
calendar: FullCalendar;
events: Lesson[];
options = {
plugins: [ dayGridPlugin, timeGridPlugin, interactionPlugin ],
header: {
left: 'prev,next',
center: 'title',
right: 'addAppointmentButton,dayGridMonth,listView,timeGridWeek,timeGridDay'
},
customButtons: {
addAppointmentButton: {
text: 'Neuer Event erfassen',
click: () => this.showEditor = !this.showEditor
}
},
eventClick: (el) => this.router.navigate(['/prime-ng']),
editable: true,
locale: 'de',
allDaySlot: false,
businessHours: {
daysOfWeek: [ 1, 2, 3, 4 , 5],
startTime: '08:00',
endTime: '18:00'
},
};
showEditor = false;
constructor(private eventService: EventService,
private router: Router) {}
ngOnInit() {
this.eventService.getEvents().toPromise()
.then( () => this.events = this.eventService.events);
}
onClose(state?: EditorState): void {
this.showEditor = !this.showEditor;
this.events = [...this.eventService.events];
}
}
Html
<app-event-editor
(close)="onClose($event)"
*ngIf="showEditor"></app-event-editor>
<p-fullCalendar
#calendar
[events]="events"
[options]="options">
</p-fullCalendar>