Change one field while changing another (ionic)

0

People, I wanted to put in the 'total' field the multiplication of the 'quantity' and 'preco_unidade' fields, how do I?

  <ion-item>
    <ion-label stacked>Preço por unidade</ion-label>
    <ion-input type="text" required placeholder="R$" [(ngModel)]="venda.preco_unidade" [value]="produto.preco_venda"></ion-input>
  </ion-item>

  <ion-item>
    <ion-label stacked>Quantidade</ion-label>
    <ion-input type="number" required [(ngModel)]="venda.quantidade" (ngModelChange)="calculaTotal()"></ion-input>
  </ion-item>

  <ion-item>
    <ion-label stacked>Total</ion-label>
    <ion-input type="number" readonly required [(ngModel)]="venda.total"></ion-input>
  </ion-item>

I have the following function in the ts:

  calculaTotal() {
    this.venda.total = this.venda.quantidade * this.venda.preco_unidade;
  }

Why is my 'total' field not being changed when I change something in 'quantity'?

Should not two-way-data-binding do this job?

How do I do it?

    
asked by anonymous 30.01.2018 / 03:58

0 answers