hsuanxyz / ion2-calendar

📅 A date picker components for ionic2 /ionic3 / ionic4
https://hsuanxyz.github.io/demo/ion2-calendar/
MIT License
555 stars 278 forks source link

load days from controller and show it on the calendar. #168

Open JoanJosep33 opened 6 years ago

JoanJosep33 commented 6 years ago

Ionic version: (check one with "x") [ ] 2.x [X ] 3.x [ ] 4.x

Ion2-calendar mode: (check one with "x") [X ] components mode [ ] modal mode

I'm submitting a ... (check one with "x") [ ] bug report [ ] feature request [X ] help me

Current behavior: Hi, I am not able to add a days from the controller into the calendar on the view. It just added when I click on some day on the calendar.

Expected behavior: How can I load the new days addeds on the array on the controller? I know there is a ViewChild, but which method can I achieve this?

aam-antonio commented 6 years ago

Hi, this is how I did it:

  loadEvents() {
    let eventsSource: DayConfig[] = [];

    this.calendarService.getEvents()
      .subscribe(response => {
        response.forEach(event => {
          eventsSource.push({
            date: event.startTime,
            marked: true,
            subTitle: event.numEvents < 5 ? "*".repeat(event.numEvents) : "****"
          });
        });

        this.options = {
          ...this.options,
          daysConfig: eventsSource
        };
      });
  }
JoanJosep33 commented 6 years ago

Hello @aam-antonio . First, thank you for your response. I have some doubts, what is the calendarService, do u have a Service, or its a component from the Calendar library?

Thank you so much!

aam-antonio commented 6 years ago

From the beginning, what you want to do is mark days?

JoanJosep33 commented 6 years ago

Yes, but if I change the month and come back, I lost the days markeds.

aam-antonio commented 6 years ago

Maybe on the monthChange event you are cleaning the daysConfig array.

Can you show your code?

soumyarout commented 6 years ago

There is a defect in marked flag, randomly automatically few days marked is coming as true. The values I set in the daysConfig is not getting reflected in Calendar.

image