Get Date range in angular-calendar view

Viewed 859

I am currently using an angular-calendar package for the Date view in the UI. I am having trouble getting the date range(start date & end date) of the view, i.e if I am currently in Monthly view, then I want the start date & end date of the monthly view & likewise for the Weekly view(start date of the week & end date of the week). How can I achieve it? I have to make the API calls according to the start date & end date of the calendar view.

2 Answers

You can use the moment library like

This Month': [moment().startOf('month'), moment().endOf('month')]
Last Year': [moment().subtract(1, 'years').startOf('years'),
              moment().subtract(1, 'years').endOf('years'),]

I solve this using " beforeViewRender " property of the "mwl-calendar-month-view" component

You just need to add the directive like this:

<mwl-calendar-month-view
   (beforeViewRender)="beforeViewRender($event)"
>

And you will have access to the start date and end date across the property "period" of the event emitter

beforeViewRender(event): void {
  console.log(event.period.start);
  console.log(event.period.end);
}
Related