如何在Angularjs中添加项目成本?

时间:2016-12-30 19:27:47

标签: angularjs angularjs-directive angularjs-scope

我想添加工作项目成本,但显示原始值。

示例:

item[1].cost =2 ,item[2].cost = 2 ..

当我添加第3 item[3].cost = 8Total = 228时。我想添加SUM,怎么做?我想要总=12

addWorkItem() {

    this.current_job.work_items.push(this.current_workitem);
    this.Total = 0;

    for (var i = 0, len = this.current_job.work_items.length; i < len; i++) {
      this.Total += this.current_job.work_items[i].cost;
    }
  this.current_workitem = {};

  }

See picture

1 个答案:

答案 0 :(得分:2)

那是因为你要对数字进行连接,而不是添加。

addWorkItem() {
  this.current_job.work_items.push(this.current_workitem);
  this.Total = 0;

  for (var i = 0, len = this.current_job.work_items.length; i < len; i++) {
    this.Total += parseFloat(this.current_job.work_items[i].cost);
  }
  this.current_workitem = {};

}