1

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.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
gil
  • 65
  • 5
  • 1
    Possible duplicate of [How to access the correct \`this\` inside a callback?](https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback) – n00dl3 Aug 01 '17 at 09:25
  • `calendarSettings: any = {properties}` is like blasphemously bad typescript. Please remove the type annotation. – Aluan Haddad Aug 01 '17 at 09:37
  • solved it. the solution would be : – gil Aug 01 '17 at 10:01

2 Answers2

1
onMonthLoaded: (event,inst) => {
    this.loadNewVisItems()parameters
}
DarthJDG
  • 16,511
  • 11
  • 49
  • 56
gil
  • 65
  • 5
0
onMonthLoaded: (event, inst) => this.loadNewVisItems(event,inst)
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Volodymyr
  • 21
  • 3