首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >全日历和角14 -访问组件函数

全日历和角14 -访问组件函数
EN

Stack Overflow用户
提问于 2022-09-01 10:06:48
回答 1查看 31关注 0票数 -1

这可能很简单,但由于某些原因,我无法从完整日历配置对象访问组件函数。

我遵循了关于如何在角14中设置完整日历的官方文档:https://fullcalendar.io/docs/v6/angular

代码语言:javascript
复制
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) { }

基本上我不能访问“这个”在事件函数中。这正常吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-01 10:15:49

目前,这是指calendarOptions,而不是使用函数关键字创建事件函数,而是使用箭头函数创建它。

示例:

代码语言:javascript
复制
events: (info, successCallback, failureCallback)=>{}

您应该能够访问this.test

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73567600

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档