这可能很简单,但由于某些原因,我无法从完整日历配置对象访问组件函数。
我遵循了关于如何在角14中设置完整日历的官方文档:https://fullcalendar.io/docs/v6/angular
import { Component, OnInit } from '@angular/core';
import { CalendarOptions, defineFullCalendarElement } from '@fullcalendar/web-component';
import dayGridPlugin from '@fullcalendar/daygrid';
import { MyHttpService } from '...';
defineFullCalendarElement();
@Component({
selector: 'app-calendar',
templateUrl: './calendar.component.html',
styleUrls: ['./calendar.component.css']
})
export class CalendarComponent implements OnInit {
test:number = 1;
calendarOptions: CalendarOptions = {
plugins: [dayGridPlugin],
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,dayGridWeek,dayGridDay'
},
events: function (info, successCallback, failureCallback) {
console.log(this.test) //Cannot read properties of null (reading 'test')
this.myHttpService.getEvents() //Cannot read properties of null (reading 'myHttpService')
.subscribe((events) => {
successCallback(this.makeEvents(events));
});
},
};
/**/
constructor(protected myHttpService : MyHttpService) { }基本上我不能访问“这个”在事件函数中。这正常吗?
发布于 2022-09-01 10:15:49
目前,这是指calendarOptions,而不是使用函数关键字创建事件函数,而是使用箭头函数创建它。
示例:
events: (info, successCallback, failureCallback)=>{}您应该能够访问this.test
https://stackoverflow.com/questions/73567600
复制相似问题