Angular 启动fullcalendar 4 eventClick发送到'/空';
嘿,每次调用eventClick()方法时,它都会执行它,然后它会路由到localhost:4200/null。但我的日历在本地主机上:4200/prime ng。因此,我尝试将路由“/null”重定向到日历路由。但是组件将被初始化为新的。然后我发现了这个帖子: 这实际上和我遇到的问题是一样的,但他是用JavaScript解决的。所以我想我可以用角度路由器做同样的事情。但它会在URL更改之前进行路由Angular 启动fullcalendar 4 eventClick发送到'/空';,angular,primeng,fullcalendar-4,Angular,Primeng,Fullcalendar 4,嘿,每次调用eventClick()方法时,它都会执行它,然后它会路由到localhost:4200/null。但我的日历在本地主机上:4200/prime ng。因此,我尝试将路由“/null”重定向到日历路由。但是组件将被初始化为新的。然后我发现了这个帖子: 这实际上和我遇到的问题是一样的,但他是用JavaScript解决的。所以我想我可以用角度路由器做同样的事情。但它会在URL更改之前进行路由 eventClick: (el) => this.router.navigate(
eventClick: (el) => this.router.navigate(['/prime-ng']),
如果你能给我一些提示和建议,我将不胜感激
组件
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>
我发现了问题。要防止它,请执行以下操作:
eventClick: (el) => el.jsEvent.preventDefault(),