twinssbc / Ionic2-Calendar

A calendar component based on Ionic framework
https://ionic-calendar-demo.stackblitz.io
MIT License
387 stars 197 forks source link

EventSource not loading events and ERROR Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError on RangeChange when event source is set #673

Closed NGC23 closed 9 months ago

NGC23 commented 9 months ago

Currently i am populating the eventsource for the calendar via an api call, i can see the array of objects are being populated when i print to the console and when i change the ranges to week it sometimes populates but i get the above expressionChanged error, i cannot seem to get my events populated on ngInit and i am creating an array of objects that is structered like the IEvent interface but i dont get any events in my calendar, please help.

public getAll(userId: string): Array<any> { let events: any[] = []; this.httpClient.get(${this.BASE_URL}/${userId}).subscribe((data: any) => { for(let i = 0; i < data.length; i++) { let startDate = new Date(data[i].start_date); events.push( { id: data[i].id, title: data[i].name, allDay: false, startTime: new Date(data[i].start_date), endTime: new Date(data[i].end_date), description: data[i].description, userId: userId } ); } }); console.log("events in service done", events); return events; }

Doing a very simple function to retrieve it but not getting it back into the calendar even if the eventSource is populated.

NGC23 commented 9 months ago

So to add to this, i have it loading now but when i change the range it looses all data.

twinssbc commented 9 months ago

@NGC23 where do you set the eventSource to the calendar? In your code, I can only see you initiate an event array and push some event in. Note that by default the calendar only watches for the whole eventSource variable change, doesn't watch for the individual element change in eventSource array. You can use loadEvents instance method to force trigger the refresh, more details in Instance Methods section.

NGC23 commented 9 months ago

Hi there i have fixed this, i was setting the event source in another function, i did not paste the entire snippet, but it seems as the events returned to quickly or the execution of events were incorrect on my side, i have managed to fix it by creating an async function where i initialise the event source on the ngOnInit function, this seems to have fixed it for me. Thanks for getting back to me, this calendar module is really cool.

But i will paste the entire code here if you want to see it, logic is still rough and needs to be cleaned but working 100% now on load and on range change. thanks again!