Navigating between different views and pages within Angular FullCalendar can be achieved by utilizing the appropriate handlers for next,

After successfully integrating Angular fullCalendar into my Angular project and displaying events that I can click on, I found myself stuck when trying to handle clicks on the next and prev buttons as well as view changes. Unfortunately, the official documentation didn't provide any guidance on how to achieve this.

Here's what I'm aiming for: When the user clicks on the next or prev buttons, I want to retrieve events corresponding to those specific days if they are in the timeGrid month view, and events related to the entire month if they are in the dayGridMonth view.

The calendar declaration in my TS file looks like this:

@ViewChild('calendar')
  calendarComponent: FullCalendarComponent;
  private eventToEdit: EventClickArg;


  // other properties
  private subscriptions: Subscription[] = [];
  calendarOptions: CalendarOptions = {
    headerToolbar: {
      left: 'prev,next today',
      center: 'title',
      right: 'dayGridMonth,timeGridDay,listWeek'
    },
    initialView: 'timeGridDay',
    themeSystem: 'bootstrap',
    weekends: false,
    locale: 'fr',
    buttonText: {
      today: 'Aujourd\'hui',
      month: 'Mois',
      day: 'Jour',
      week: 'Semaine'
    },
    editable: true,
    selectable: true,
    selectMirror: true,
    dayMaxEvents: true,
    slotDuration: '00:15:00',
    select: this.handleDateSelect.bind(this),
    slotMinTime: '08:00:00',
    slotMaxTime: '22:00:00',
    eventClick: this.handleEventClick.bind(this),
    eventBackgroundColor: '#089bab',
    eventBorderColor: '#089bab',
  };

Below is the HTML code for the component:

<div class="card">
        <div class="card-body">
          <div class="row">
            <div class="col">
              <full-calendar #calendar
                             [options]='calendarOptions'></full-calendar>
            </div>
          </div>
        </div>
      </div>

Answer №1

Attention all readers, I stumbled upon a variable named datesSet that I link to a handler function, which is triggered every time a date is altered. Behold the updated TS file:

calendarOptions: CalendarOptions = {
    // ... identical properties as in the original query
    datesSet: this.handleDateChanged.bind(this) };

  handleDateChanged(arg) {
    this.logger.debug('your view is:', this.calendarComponent.getApi().view);
    this.calendarComponent.getApi().removeAllEvents();
    if (this.calendarComponent.getApi().view.type === 'timeGridDay') {
      this.retrieveAllAppointments(this.calendarComponent.getApi().getDate(), this.calendarComponent.getApi().getDate(), null);
    } else if (this.calendarComponent.getApi().view.type === 'dayGridMonth') {
      this.retrieveAllAppointments(arg.start, arg.end, null);

    } else if (this.calendarComponent.getApi().view.type === 'listWeek'){
      this.retrieveAllAppointments(arg.start, arg.end, null);
    }   
}

The method retrieveAllAppointments triggers my Rest API call.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring methods for efficiently handling extensive XLSX files in a Node.js environment

Currently, I am utilizing the ts-xlsx library on the server side to read data. The process involves reading data from the frontend as a byte array using file-reader and then sending this byte array to a library to process the data. However, in cases where ...

The angular material navigation bar is refusing to open the dropdown menus

I am currently working on an angular project where I want to implement a collapsible menu for users after they log in. However, the code I have written for the material nav bar is not functioning as expected when clicked. <mat-toolbar color="pr ...

Achieving CommonJS imports compilation with Typescript

In my TS file, I've included a 3rd party package using import XXX { YYY, ABC, 123 } from 'XXX'; While it compiles to CommonJS without any issues, I'd prefer to have it compiled to an ESModule instead. I tried changing the target and mo ...

Switch up text colors on the fly in Angular as you type!

I've been developing a Note Taking application where users can type in red text. Additionally, they should also have the ability to change the color of the remaining text to black while typing. ...

Displaying object properties in React and rendering them on the user interface

Within my React application, I am retrieving data from an API using the following code snippet: function PlayerPage() { interface PlayerDataType { id: number; handle: string; role: string; avatar: string; specialAbilities: null; s ...

Troubleshooting issue: matTooltip malfunctioning in *ngFor loop after invoking Angular's change

The matTooltip in the component below is rendering correctly. The overlay and small bubble for the tooltip are rendered, but the text is missing (even though it's present in the HTML when inspecting in the browser) and it isn't positioned correct ...

Error: Protractor encountered an unexpected token while trying to import an external class

While working on my Protractor test, I encountered a syntax error on import when trying to bring an external class into the test. The strange thing is that the error only occurs at runtime, even though I am confident that I am importing and exporting the c ...

Ensuring a child element fills the height of its parent container in React Material-UI

Currently, I am in the process of constructing a React Dashboard using MUI. The layout consists of an AppBar, a drawer, and a content area contained within a box (Please correct me if this approach is incorrect)... https://i.stack.imgur.com/jeJBO.png Unf ...

Understanding the infer keyword in Typescript when working with generic type constraints

Exploring a scenario where I have a generic interface that requires a type argument extending another generic type. export interface IPoint<TX, TY> { x: TX; y: TY; } export interface ISeries<TPoint extends IPoint> { points: Array& ...

The field list contains an unidentified column named 'Test.computerIDComputerID'

I am currently navigating through the syntax of typeORM and have been stuck troubleshooting an issue for quite some time. It appears that whenever I utilize the find() function in typeORM, a query is generated with a duplicated column from a relation. Here ...

Leveraging the Map function with Arrays in TypeScript

Is there a way to dynamically render JSON data into a component using array.map in Typescript? I am running into an error with the code snippet below. const PricingSection: FC<IProps> = ({ icon, title, price, user, observations, projects, intervie ...

What is the process of transforming an object type into a two-dimensional array using lodash?

In order to properly display multiple tables in my Angular project, I am looking to convert an object type into an array of different objects. The object I am working with is as follows: let myObject = { internalValue:{city:"Paris", country:"France", pin ...

What is the best way to organize the data retrieved from the api into a map?

In my search page component, I display the search results based on the user's query input. Here is the code snippet: "use client"; import { useSearchParams } from "next/navigation"; import useFetch from "../hooks/useFetch&qu ...

Assign a class to a DIV element depending on the ID of an object using Angular

I'm trying to dynamically add a class to a div based on the id of a field in an object. However, my code doesn't seem to be working as expected. Can someone help me debug this? <ng-container *ngFor="let item of cards"> <d ...

How to manipulate dates using Angular 2's date pipe to add or subtract hours

I am encountering an issue with the new Angular 2 Date Pipe. My date value is as follows: let myDate = '2017-01-31T17:53:36' When I use the Date Pipe to format it in the view like this; {{myDate | date: 'dd/MM/yyyy HH:mm' }} It dis ...

What steps can be taken for TypeScript to identify unsafe destructuring situations?

When working with TypeScript, it's important to prevent unsafe destructuring code that can lead to runtime errors. In the example below, trying to destructure undefined can cause a destructuring error. How can we ensure TypeScript does not compile suc ...

Designing the Pull to Refresh feature in Nativescript Angular

I've been experimenting with the Nativescript Angular Pull to Refresh Styling demo (Link) and I'm running into an issue where this.myListViewComponent remains undefined, causing the following snippet not to trigger: if (this.myListViewComponent ...

Can a new class be created by inheriting from an existing class while also adding a decorator to each field within the class?

In the following code snippet, I am showcasing a class that needs validation. My goal is to create a new class where each field has the @IsOptional() decorator applied. export class CreateCompanyDto { @Length(2, 150) name: string; @IsOptional( ...

What is the best way to fake the retrieval of '$location' using mock for angular.element(document).injector() in jasmine 3.6?

Currently, I am encountering an issue. I am unsure of how to mock the following method: private angularLocation = angular.element(document).injector().get('$location'); In my hybrid angular application, this method is crucial for navigating betw ...

Making all requests server-side in Next.JS: A step-by-step guide

I am in the process of creating a Next.JS application that will be retrieving data from both a Python API and a Postgres Database. Although this task may seem straightforward, the project requirements dictate that all requests must originate from the serv ...