Delete chosen file from a list and subtract from the total value - Ionic

Asked

Viewed 32 times

0

I’m developing an app with Ionic 3 and Firebase. I am facing problems, because it is not decreasing the value of the product(chosen) of the total. Always subtract the last value informed. Follows the code :

deleteProduto(element) {
 if(this.vetCarrinho.length > 1){
   this.vetCarrinho.splice(this.vetCarrinho.indexOf(element), 1); 
   this.acum = (this.acum - this.valTot); 
   this.pedido.total = element; 

save function :

irParaCarrinho(element) {  
element = this.pedido.carrinho;    

this.vetCarrinho.push(element);  
console.log(this.vetCarrinho);
this.pedido.carrinho = this.vetCarrinho;

for (let i = 0; i < this.vetCarrinho.length; i++) {
    this.acumulador = this.valTot;       
  }    
  this.acum += this.acumulador;
  this.pedido.total = this.acum;
  this.desabilitar = true;  
  • Which variable is returning wrong value? Is the this.acum? What is the this.valTot? Shouldn’t it be the value of the element? Something like element.valor.

  • The products have the total value (this.valTot) that would be, the sale price x quantity. In the list of products, when I try to exclude a product, it always decreases from the total, this.valTot, from the last element.

  • I believe that it would be best to check the total value of the element within the function deleteProduto(element), which is where you tell which element will be deleted. The variable element stores the total value or selling price and quantity of the product?

  • I am storing the products informed, in a vector, but I am not stating their price. I analyzed coldly and saw that the mistake is this. Here is another question: How do I store the product and its price in the vector, and then subtract the value of the chosen element ?

  • If you post the rest of the code it is easier to understand your problem. For example, where does the element?

  • I edited the question

Show 1 more comment
No answers

Browser other questions tagged

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