Encountered issue when attempting to insert items into the list in EventInput array within FullCalendar and Angular

I am struggling to create a dynamic object that I need to frame and then pass to the FullCalendar event input. Here is my initial object:

import { EventInput } from '@fullcalendar/core';
...
events: EventInput[];    
this.events = [ { title: '', allDay: false, start: choosenStartDate, end :choosenEndDate, backgroundColor: RateColor.SpecialRate, borderColor: RateColor.SpecialRate },];  

If I have multiple objects, I want to push them into an array, but I'm encountering issues.

let obj1:EventInput = { title: '', allDay: false, start: specialRateStartDate, end :specialRateEndDate, backgroundColor: RateColor.SpecialRate, borderColor: RateColor.SpecialRate };
let obj2 :EventInput= { title: '', allDay: false, start: normalRateFirstStartDate, end :normalRateFirstEndDate, backgroundColor: RateColor.NormalRate, borderColor: RateColor.NormalRate };
let obj3:EventInput = { title: '', allDay: false, start: normalRateSecondStartDate, end :normalRateSecondEndDate, backgroundColor: RateColor.NormalRate, borderColor: RateColor.NormalRate }

When I try this.events.push(obj1);, I get the error

ERROR TypeError: Cannot read property 'push' of undefined
.

One solution that works is setting

this.events=[obj1,obj2,obj3,obj4,obj5...];
, however, I prefer inserting them through a loop.

Answer №1

Make sure to include = []; when declaring an array:

events: EventInput[] = [];    

It's important to initialize the array!

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

What is the best way to initiate multiple processes in Node.js and ensure they finish before proceeding?

When working with Node.js and TypeScript, my goal is to initiate multiple processes using the spawn function. Afterwards, I aim to ensure all of these processes are completed before proceeding to execute any additional commands. ...

Adding an arrow to a Material UI popover similar to a Tooltip

Can an Arrow be added to the Popover similar to the one in the ToolTip? https://i.stack.imgur.com/syWfg.png https://i.stack.imgur.com/4vBpC.png Is it possible to include an Arrow in the design of the Popover? ...

What is the method for selecting the desired month on a primeng calendar with multiple selection enabled?

I am looking for a solution to make my inline primeNg Calendar display the month of a specific date in the model, and when I remove dates from the model, I want it to show the current month. I have tried using defaultDate={{value}} and minDate={{value}}, a ...

Tips for utilizing 'safe-json-stringify' within Angular 4 Application

I have a specific requirement to convert a JSON object to a string. However, simply using JSON.stringify() does not work due to circular references. After some research online, I came across a package that can handle this issue for me. The only problem is ...

The *ngIf directive is refusing to display a template

I am currently facing an issue with my .html file where I am trying to display values based on a condition using "*ngIf". The condition is to find a value that ends with "Rechercher ...", but I am having trouble getting it to work. I have tried various app ...

Global Inertia Headers

How can I ensure that a custom header (Accept-Content-Language) is sent with every request, including Inertia manual visits? Below is the code snippet where I define and set the header: import axios from 'axios'; const lang = localStorage.getIt ...

How can I retrieve a password entered in a Material UI Textfield?

My code is functioning properly, but I would like to enhance it by adding an option for users to view the password they are typing. Is there a way to implement this feature? const [email, setEmail] = useState(''); const [password, setPassword] = ...

What is the best way to implement a dispatch function in TypeScript?

Despite my expectations, this code does not pass typechecking. Is there a way to ensure it is well typed in Typescript? const hh = { a: (_: { type: 'a' }) => '', b: (_: { type: 'b' }) => '', } as const; ex ...

The element class type 'xxx' is lacking several properties compared to the 'ElementClass' type, including context, setState, forceUpdate, props, and others. This issue is flagged with error code TS2605

Encountering an error while attempting to execute my react app: D:/React/my-components/src/App.tsx TypeScript error in D:/React/my-components/src/App.tsx(23,4): JSX element type 'Confirm' is not a constructor function for JSX elements. ...

What causes TypeScript to overlook the generic constraint within a function?

Here is a simple illustration of what I am trying to convey: type Shape = 'square' | 'circle'; type Params<S extends Shape> = S extends 'square' ? { side: number } : { radius: number }; function getArea<S ...

Angular Inner Class

As a newcomer to Angular, I have a question about creating nested classes in Angular similar to the .NET class structure. public class BaseResponse<T> { public T Data { get; set; } public int StatusCo ...

The issue I encountered with Angular's Mat-Select component is that the openedChange

When a user opens the mat-select, I am attempting to set CSS style using custom code. However, I am encountering an undefined error. Upon checking in the console, I noticed that the panel value is returning undefined. Can someone please advise me on how to ...

Is there a way to transform individual data into a collective group dataset?

Here is the input data provided: data = [ { name: "John Cena", groupName: "WWE" }, { name: "Nandini", groupName: null }, { name: "Rock", groupName: "WWE" }, { name: "Vinay", groupName: null }, { name: "Rey Mesterio", groupName: "WWE" ...

Generating ambient module declarations in Typescript for distribution on NPM

Seeking advice on generating TypeScript ambient module declarations for a node (commonjs) npm package being developed in TypeScript. Encountering confusion around the proper method to have TypeScript create these ambient module declarations for node / comm ...

Access uninitialized properties in Typescript post-compilation

I am currently in the process of creating a wrapper for socket.io. Coming from a strong object-oriented background, I aim to incorporate the idea of Models into my framework/wrapper. For those familiar with socket.io, you may know that data associated wit ...

I recently installed Angular version 12, but another unexpected version 13 was also installed simultaneously. I only wanted version 12, so now I need to figure out how to uninstall

C:\Users\eaind>npm install -g @angular/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96f5faffd6a7a4b8a6b8a4">[email protected]</a> Upon installing version 12 in the directory C:\Users\eaind&bso ...

What is the appropriate directory to place the `typescript` package in order for WebStorm to recognize it?

According to the information on this webpage: The Configure TypeScript Compiler dialog box provides two options: Detect: WebStorm will look for a typescript package within the current project. If it finds one, it will use that package. Otherwise ...

Divide Angular ngFor into separate divs

Here is an example of my current array: [a, b, c, d, e, f, g, h, i] I am aiming to iterate through it using ngFor and split it into groups of 3 elements. The desired output should look like this: <div class="wrapper"> <div class="main"> ...

Ways to create an HTTP request by monitoring when users click outside of an input field

I am struggling to figure out how to achieve this in angular 2. I want to make an http request a few seconds after the user clicks out of the input box. The request should be based on the user's input. Any suggestions on how to accomplish this? I have ...

convert a JSON object into an array field

I am looking to convert a list of objects with the following structure: { "idActivite": 1, "nomActivite": "Accueil des participants autour d’un café viennoiseries", "descriptionActivite": "", "lieuActivite": "", "typeActivite": "", ...