我正在尝试以角度5初始化类的数组。
export class B{
public Colors: string;
public Temp: number;
public Numbers: number;
}
export class A{
public MyTable: B[];
public othervar: number;
...
...
}
然后我尝试像这样初始化MyTable:
var test = new A();
test.MyTable[0].Numbers = 25;
test.MyTable[0].Colors= "blue";
这是正确的吗?
答案 0 :(得分:1)
您还有new B()
的新用法:
const test = new A();
test.MyTable = [];
test.MyTable[0] = new B();
test.MyTable[0].Numbers = 25;
test.MyTable[0].Colors= "blue";