mobiscroll events and typescript functions

618 views Asked by At

I want to use the mobiscroll event for the calendar object (onMonthLoaded) but instead of writing all code inside the settings element of the mobiscroll - have the logic outside of it.

This is my code:

   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());
    }
}

I want to be able to call the loadNewVisItems method from within the onMonthLoaded handler. syntax wise it does not recognise the method when I just do a simple call to it by using either this or any other way.

2

There are 2 answers

0
gil On
onMonthLoaded: (event,inst) => {
    this.loadNewVisItems()parameters
}
0
Volodymyr On
onMonthLoaded: (event, inst) => this.loadNewVisItems(event,inst)