Utilizing TypeScript
for coding in Angular2, I am dealing with this object:
export class Vehicle{
name: String;
door: {
position: String;
id: Number;
};
}
To initialize the object, I have followed these steps:
constructor() {
this.door = new Door();
}
export class Door{
position: String;
ID: Number
}
Everything works smoothly at this point. However, things get complicated when I attempt to initiate an array of objects.
export class Vehicle{
name: String;
door: {
position: String;
id: Number;
};
color: {
tone: String;
shade: String;
}[]
}
Attempting the same resulted in the following
constructor() {
for (var i = 0; i < 10; i++) {
this.color.push(new Paint);
}
this.door = new Door();
}
export class Paint{
tone: String;
shade: String;
}
The encountered error is as follows:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'push' of undefined TypeError: Cannot read property 'push' of undefined