How to add values in the keyup using angular?

0

I have a field that I need as I type values, it will add up to a variable.

I tried something like:

<input (keyup)="somaEstoque($event)"  #inputestoque type="text" name="estoque_variacao{{i}}" class="form-control" id="estoque_variacao{{i}}" formControlName="estoque_variacao">

  somaEstoque(valor){
    this.produto.estoque = this.produto.estoque + toFloat(valor.target.value);
  }

My target to be added is a formgroup that can have "N" stock inputs:

<div class="col-12 col-md-2">
    <div class="md-form form-lg input-modal">
       <input mask="000000000000" (keyup)="somaEstoque($event)"  #inputestoque type="text" name="estoque_variacao{{i}}" class="form-control" id="estoque_variacao{{i}}" formControlName="estoque_variacao">
       <label [class.active]="inputestoque.value != ''" for="estoque_variacao{{i}}">Estoque</label>
    </div>
</div>

I think logic is a bit more complex, and it also has to deal when the user deletes the value.

Has anyone done this in the angle?

    
asked by anonymous 17.10.2018 / 14:22

1 answer

0

Who cares, I did it this way:

  soma(){
    let sum = 0;
    Object.keys(this.controls).map(key => {
      sum +=  +this.controls[key];
    });
    this.produto.estoque = sum;
  }

 <input mask="000000000000" [(ngModel)]="controls[i]" (keyup)="soma($event)" #inputestoque type="text" name="estoque_variacao{{i}}" class="form-control" id="estoque_variacao{{i}}" formControlName="estoque_variacao">
    
17.10.2018 / 15:23