1
我想爲日曆對象(onMonthLoaded)使用mobiscroll事件,而不是在mobiscroll的設置元素內寫入所有代碼 - 將邏輯放在它之外。mobiscroll事件和打字稿功能
這是我的代碼:
export class CalendarComponent {
constructor(private sessionService: SessionService,
private visItemsService: VisibleItemsService,
) {
this.visItemsService.visItems$.subscribe(items => {console.log("got these New visible items : ", items)});
}
calendar: Date = new Date();
calendarSettings: any = {
theme: 'timelord',
display: 'inline',
layout: 'liquid',
controls: ['calendar'],
cssClass: 'tl-cal',
max: new Date(2030,12,31),
min: new Date(2005,1,1),
onDayChange: function (event,inst) {
// event.date returns the selected date in date format
// console.log('date '+event.date);
},
onMonthChange(event,inst) {
// console.log('changed');
// console.log(event.year);
// console.log(event.month); // 0-11
},
onMonthLoaded(event,inst) {
console.log('lloaded');
// console.log(event.year);
// console.log(event.month); // 0-11
// console.log('month :'+inst.getVal());
}
};
loadNewVisItems(year: number,month:number) {
console.log('in load New!');
let timeRangeStart = moment().year(year).month(month).date(1).hour(0).minutes(0).second(0);
let timeRangeEnd = timeRangeStart.add(1,'month').subtract(1,'second');
this.visItemsService.setTimeRange(timeRangeStart.unix(),timeRangeEnd.unix());
}
}
我希望能夠從onMonthLoaded處理程序中調用loadNewVisItems方法。語法上它不能識別該方法,當我只是通過使用這個或任何其他方式進行簡單的調用。
可能重複[如何在回調中訪問正確的\'this \'](https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-在回調中) – n00dl3
'calendarSettings:any = {properties}'就像褻瀆糟糕的打字稿。請刪除類型註釋。 –
解決了它。解決方案將是: – gil