Sum returns NAN even by converting the number to angular

0

I have a repeat structure that should add up some values:

The variable qtdeEstoque has been defined as number and the variable variacaoForm.value.variacoes.estoque_variacao is a number, but when I try to add this way instead of incrementing the value it puts in front, for example: number 10 and 5 , it joins and stays 105 :

  for(let i=0;i<this.variacaoForm.value.variacoes.length;i++){
       this.qtdeEstoque+= this.variacaoForm.value.variacoes[i].estoque_variacao
  }
  console.log(this.qtdeEstoque);

I tried some other ways using toInt() and Number() :

  for(let i=0;i<this.variacaoForm.value.variacoes.length;i++){
    this.qtdeEstoque+= Number(this.variacaoForm.value.variacoes[i].estoque_variacao)
  }
  console.log(this.qtdeEstoque);

But it returns NAN , how can I fix this?

    
asked by anonymous 25.09.2018 / 13:42

1 answer

2

App

this.qtdeEstoque = 0;  
for(let i=0;i<this.variacaoForm.value.variacoes.length;i++){
       this.qtdeEstoque+= this.variacaoForm.value.variacoes[i].estoque_variacao
  }
  console.log(this.qtdeEstoque);

Tips:

When you add the value public qtdeEstoque: number = 0 you can get ahead in one go

    
25.09.2018 / 13:46