Angular如何插入一个接口的1个数据

时间:2019-04-26 12:00:37

标签: angular typescript interface

export interface _ProjectBudgetHistories {
  createdBy?: string ;
  id?: number;
  budgetYear? : number ;
  logicalFrameworkId? : number  ;
  projectId?: number ;
  amount?: number ;
  mooe?: number ;
  co?: number;
}

pbHistories : _ProjectBudgetHistories;
let co =500;
let mooe =1000;

this.pbHistories.co = co;
this.pbHistories.mooe = mooe;

console.log(this.pbHistories);

这是错误TypeError:无法设置未定义的属性'co'  TypeError:无法设置未定义的属性“ mooe”

=== >>如何仅更新mooe和co ???

1 个答案:

答案 0 :(得分:0)

初始化您的财产

pbHistories : _ProjectBudgetHistories = {};