When displaying the total value the code is looping - ANGULAR 11

Asked

Viewed 37 times

0

Good afternoon!

I’m retrieving some values from mongodb and summed to display the result on screen, but the code has looped.

Someone could help me!

Follows the code!

 get recuperaValorTotal(){
    let valorTotal: Array<any> = [];
    for(let contas of this.contasService.contas){
      valorTotal.push({
        valor: contas.valorTotal
      });
      this.valorCalculado += parseFloat(contas.valorTotal.toString());
    }
    Swal.fire('Valor Total: ' + 'R$' + this.valorCalculado.toFixed(2));
    return this.valorCalculado.toFixed(2);
  }

In this.countsService.contas I have the following fields:

export class ContasService {
  selectConta: Contas = {
  _id: '',
  descricao: '',
  valorTotal: '',
  vencimento: '',
  status: ''
  };

  contas: Contas[];

A JSON

{
"descricao": "teste",
"valorTotal" : "200.00",
"vencimento" : "2021-01-19",
"status" : "Pendente"

}
  • 1

    Supplement your code better so we can better understand what’s in this.account variable.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.