mobiscroll事件和打字稿函数

问题描述 投票:1回答:2

我想使用mobiscroll事件作为日历对象(onMonthLoaded),而不是在mobiscroll的settings元素中编写所有代码 - 在它之外有逻辑。

这是我的代码:

   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方法。语法方面,当我只是通过使用这个或任何其他方式对它进行简单调用时,它无法识别该方法。

angular typescript event-handling mobiscroll
2个回答
1
投票
onMonthLoaded: (event,inst) => {
    this.loadNewVisItems()parameters
}

0
投票
onMonthLoaded: (event, inst) => this.loadNewVisItems(event,inst)
© www.soinside.com 2019 - 2024. All rights reserved.