mattlewis92 / angular-calendar

A flexible calendar component for angular 15.0+ that can display events on a month, week or day view.
https://mattlewis-github.com/angular-calendar/
MIT License
2.71k stars 864 forks source link

infinite before view render calls #1695

Open SirAlfred0 opened 8 months ago

SirAlfred0 commented 8 months ago

Describe the bug

hello @mattlewis92, I'm experiencing some issues with your package. as you can see in the below screenshot beforeViewRender event calls infinite times when I try to feed events to the calendar lazily here is my code

  <mwl-calendar-month-view
    *ngSwitchCase="'month'"
    [viewDate]="viewDate"
    [events]="events"
    [activeDayIsOpen]="true"
    [refresh]="refresh"
    (eventTimesChanged)="eventTimesChanged($event)"
    (beforeViewRender)="onViewRender($event)"
  >

and the logic

  onViewRender(viewRenderEvent: any): void
  {
    const start = new Date(viewRenderEvent.period.start).toISOString();
    const end = new Date(viewRenderEvent.period.end).toISOString();

    console.log(start, end);
    setTimeout(() => {
      this.events = e.filter(ev => ev.start.toISOString() >= start && ev.end?.toISOString()! <= end);
    });

  }

just so you know this is just a demo in a real application I'm gonna fetch the events from the server via period.start and period.end.

image

matts-bot[bot] commented 8 months ago

Thanks so much for opening an issue! If you'd like to support this project, then please consider sponsoring me