Why aren't my arrays' characteristics being recognized when I create an instance of this class?

There is a puzzling issue with the arrays in my class. Despite creating them, when I try to access them in another class they are not recognized, only the otherProp is visible. To make matters worse, attempting to add elements to the arrays results in an error because myArray1 or myArray2 is apparently undefined. I have experimented with different ways of initializing the arrays, such as using "any[]" and setting them as empty upon creation, but none of these methods have resolved the issue.

export class MyModel{
    myArray1: Array<{dias: Array<number>, amount: number}>
    otherProp: number                   
    myArray2: Array<{month: number, amount: number}>

    Constructor(){        
        this.otherProp= 0;
        this.myArray1= new Array<{dias: Array<number>, amount: number}>();
        this.myArray2 = new Array<{month: number, amount: number}>();
    }
}

Answer №1

constructor needs to be in lowercase in order for it to work properly. If it's not in lowercase, it won't get called. Also, since otherProp is a primitive type, it will automatically be initialized to the default value of 0.

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

I'm encountering an issue where the npm install process is getting stuck while attempting to extract the xxxx package

When running the sudo npm install command on my local machine, everything works fine. However, once I pulled the code into an EC2 Ubuntu machine, the npm install process gets stuck at a certain point. The output shows "sill doParallel extract 1103" and I ...

Skip over any null values in Angular

As someone new to Angular, I have a function in a component that makes API calls and expects results, but errors can also occur. this.Service.callAPI(). .subscribe(data => { if(data?.errors){ }); The issue is arising because both ...

JavaScript code to calculate the total of elements in a multi-dimensional array

I am working on a JavaScript project where I need to calculate the sum of each subarray using forEach, map, and reduce functions. My goal is to have an output like this: sum = [8, 13, 22] However, despite my efforts, I cannot seem to get the desired outc ...

What is the best way to retrieve an array of model objects utilizing a resolver?

I utilize a resolver to fetch data from the server import {Resolve, ActivatedRoute} from "@angular/router"; import {Observable} from "rxjs"; import {RouterStateSnapshot} from "@angular/router"; import {ActivatedRouteSnapshot} from "@angular/router"; imp ...

What is the process for setting a default checkbox as checked in Angular 6?

example.component.html <form method="post" enctype="multipart/form-data> <mat-checkbox class="style" name="checkboxenabled"[(ngModel)]="checkboxObj.checkboxenabled">Enabled</mat-checkbox> </form> I have been trying to set the c ...

Establishing a server in Node.js alongside an Angular 2 frontend by harnessing the power of Typescript

I'm looking to deploy my web application on IBM Bluemix with Angular 2 using Typescript for the frontend and Node.js for the backend. Can you advise me on how to configure the server, connect it to the frontend, and specify which transpiler I should u ...

Interactive form control for location details including country, state, district, and town

I am struggling with adding dynamic form controls on dropdown change. I have been able to add them, but encountered an error preventing me from retrieving the value in 'formName.value'. The specific error message states: "Error: There is no Form ...

Resetting the state back to its initial value - which one to use: useState or useReduce?

In order to enhance the functionality of a third-party Authentication service Auth0's useAuth0 hook, I have developed a custom hook called useAuth. This custom hook is responsible for managing local variables that store essential user information like ...

Sort by the recent messages of another observable

I'm attempting to sort through messages in one observable based on the messages from another observable. navCmds --A----B---C--A------D-----------------C-----D----E---> navNotifications ----A----X---B-C-A---D------------------------DCA-- ...

Incorporating items into a dynamic array using MobX

Issue with Pushing MobX Objects to an Observable Array I'm facing a challenge when trying to push objects into an observable array in MobX and iterate over them successfully. At the starting point, I initialize the observable array: if (!self.selec ...

What is the method to merge min and max validation errors when using React Hook Form?

<input {...register("subject", { maxLength: 50, minLength: 2, required: true, })} disabled={isLoading} id="subject" autoComplete=&q ...

The class function in the exported typescript logs that "this" is not defined

I am currently facing an issue with my TypeScript class where I am setting class values in a constructor and referencing them using "this" in a class method. While the .ts file compiles without any warnings, when I import the compiled .js file into another ...

Generating an instance of an enum using a string in Typescript

Having trouble accessing the enum members of a numeric enum in TypeScript using window[name]. The result is an undefined object. export enum MyEnum { MemberOne = 0, MemberTwo = 1 } export class ObjectUtils { public static GetEnumMembers(name ...

Angular 8: Issue encountered while resolving parameters for TextAreaEditorComponent

After upgrading angular to version 8.2.14, I attempted to convert the below code from a class to a component. However, I encountered the following error: ERROR in Can't resolve all parameters for TextAreaEditorComponent The issue seems to be with th ...

Ways to simulate a service using get() method with a particular data structure

I've been working on writing unit tests for my component and simulating a service that makes HTTP requests. The response data structure looks like this: { ContactActivityView :[ { Code:"AB", IsActive:false, }, ...

The image located in the wwwroot directory is not displaying when the <img> tag is used. What could be causing this issue in ASP.NET and Angular?

My current project is housed in a folder named 'UsedCarsShop', which contains two subfolders: Frontend Within this folder is the 'UsedCarsShopFrontend' folder, where the Angular project is located. Backend The 'CarWebShop&apos ...

Guide to creating a SVG component using typescript in a React application

I have a component where I am passing SVG icons props as an array containing my SVG component data. However, TypeScript is showing me an error while working with Material UI. Type '{ key: number; data: { id: number; icon: ReactNode; }; }' is not ...

Angular 2 component stays static despite changes in route parameters

So, I am in need of a way to refresh my component after the URL parameter's id has been altered. The following code is from my player.component.ts: import {Component, OnInit, AfterViewInit} from '@angular/core'; import {ActivatedRoute, Rout ...

Comparing Angular2 Material and Bootstrap: Which one is the better

Forgive me if this sounds like a basic question, but I could really use some guidance. I'm in the process of developing a new application and I can't decide between using angular2 material or bootstrap. ...

Function useAppDispatch is missing a return type

.eslintrc.js module.exports = { root: true, extends: [ '@react-native-community', 'standard-with-typescript', 'plugin:@typescript-eslint/recommended', 'plugin:jest/recommended', 'plugin:p ...