Value doubling after ticking the second toogle button

0

I'm having a problem marking the toogle button. What happens is as follows, I created a function that captures the items that are marked TRUE on the toogle button, and pass them as a parameter to the next screen, along with the quantity, and then finalize the sale of the items in question. / p>

It turns out that I have to add the total value of the products, so I thought of the following case, create an array only of the values that are marked and send as a parameter to the other screen, so there I only do the calculation and display it in the screen, without having to map the entire array to find the values.

However in the tests the following is happening, I choose the first item that is 20.99 it captures quietly, but when I click on a second item that costs 20.00 for example, it captures the 20.00 but captures again or 20.99.

Does anyone know why this happens?

  productsCart(event) {
//captura os itens que foram marcados no toogle e joga para a matriz productsSale
this.productsSale = this.products.filter(teste => {
  //retorna só os itens que foram marcados como true no toogle
  if (teste.checked == true){
      console.log(teste.preco);
      //Aqui ocorre a mesma coisa, quando eu tento selecionar um novo produto
      //ele duplica o valor do anterior e duplica o valor do atual.
      this.valueAll.push(teste.preco);
  }
  return teste.checked;   
})

}

  constructor(public navCtrl: NavController, 
          public navParams: NavParams,
          public produtosProvider: ProdutosProvider) { 

          this.produtosProvider.getAll()
            .subscribe( produtos=> {
              this.products = produtos;
              this.loadedProductList = produtos;
            })

          this.valueAll = []; //meu array que quero montar apenas com os preços dos produtos
          this.productsSale = []; //esse array passa o objeto inteiro para a outra tela
          +this.qtd;

}

 <ion-toggle class="toogle-button"
             (ionChange)="productsCart($event)" [(ngModel)]="item.checked">
 </ion-toggle>

Here are the images of how you have returned me on the console:

AdetailIjustnoticed(5thimage).

    
asked by anonymous 28.11.2018 / 21:34

0 answers