单击此处查看我的代码
import { OnInit } from '@angular/core';
import { HelpersService } from 'src/app/helpers.service';
@Component({
selector: 'app-system-maintenance',
templateUrl: './system-maintenance.page.html',
styleUrls: ['./system-maintenance.page.scss'],
})
export class SystemMaintenancePage implements OnInit {
constructor(
public helpers : HelpersService,
) {}
calendarVisible = false;
calendarOptions: CalendarOptions = {
headerToolbar: {
center: 'prev,today,next',
left: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay',
},
initialView: 'dayGridMonth',
// initialEvents: INITIAL_EVENTS,
weekends: true,
editable: true,
nextDayThreshold: '00:00:00',
events: [
{
// Goes from 8pm to 10am the next day.
title: 'Event 2',
start: '2020-12-04T00:00:00',
end: '2020-12-06T00:00:01',
allDay : true,
html : true,
}
],
eventDidMount: function(info) {
/// console.log(info);
},
eventDrop: function(info) {
/// alert(info.event.title + " was dropped on " + info.event.start.toISOString() + ' to '+ info.event.end.toISOString());
if (!confirm("Are you sure about this change?")) {
info.revert();
}else{
this.helpers.update_sched(info.event);
}
},
selectable: true,
displayEventTime : true,
selectMirror: true,
// dayMaxEvents: true,
};
我不能在eventDrop中的助手服务中使用我的函数,它说未定义。在将事件丢弃到特定日期之后,它说";ERROR TypeError:无法读取未定义的"的属性"helpers";。。
编辑:为我的问题添加了一些代码文本。
确实清楚地表明,我将隔离您对所拥有对象的定义,。。。
eventDrop: function(info) { /* this is where your mistake is */
/*
with the keyword 'function', this refers to the function object from JS, so
to fix it you need to change to arrow function...
*/
if (!confirm("Are you sure about this change?")) {
info.revert();
} else{
this.helpers.update_sched(info.event);
}
},
所以在箭头函数的方式中,它看起来是这样的。
eventDrop: (info) => { /* this is where your mistake is */
/*
with the keyword 'function', this refers to the function object from JS, so
to fix it you need to change to arrow function...
*/
if (!confirm("Are you sure about this change?")) {
info.revert();
} else{
this.helpers.update_sched(info.event);
}
},