原始异常:无法读取未定义的属性'push'



我有一个打字稿类,它有一个数组项podetails。

POheader class:
import { POdetail } from './podetail';
export class POheader {
  public PO_Number: string;
  public podetails: [POdetail];
  constructor(
  ) {
  }
}

我初始化了它:

poheader: POheader = new POheader(); 

但是当我推送时,它会给出此错误。

这是推送语句:

this.poheader.podetails.push({
  Item: this.NewItem,
  description: this.NewDescription
});

错误:

ORIGINAL EXCEPTION: Cannot read property 'push' of undefined

在将数据推送到podetails之前,使用空数组初始化。

公共信息: [POdetails];

更改为

公共信息:POdetail[] = [];

最新更新