Skip to content Skip to sidebar Skip to footer

Array Of Arrays In Typescript

I'm trying to add an object array to an array in TypeScript (for an Angular 2 app). Here's a stripped down and simplified version of my code: mylist.ts: export class myList { c

Solution 1:

You're not binding to a property of MyList thus your object is empty.

Change your class to the following

exportclassmyList {
    constructor(public Number1: number,
        public String1: string){}
}

By adding public or private TypeScript will create properties for you. Now the result will be:

[{Number1: val, String1: val}]

Solution 2:

You never set properties of the myList object in its constructor. Try this:

exportclassmyList {
    constructor(Number1: number, String1: string) {
        this.number = Number1;
        this.string = String1;
    }
}

Post a Comment for "Array Of Arrays In Typescript"