Guys, how’s it going? I need a help with a toogle button.
I build a list of products, where each product has a toogle button, and the idea is, when I check the toogle button this marked item goes to an array, that array will be of the products that the user will buy, and will be passed as parameter to the shopping cart page.
Currently my list of items has only two items. And when I select just ONE of these items, it marks the TWO items, I can not find what I did wrong
constructor(public navCtrl: NavController,
public navParams: NavParams,
public produtosProvider: ProdutosProvider) {
this.produtosProvider.getAll()
.subscribe( produtos=> {
//I capture all the products of the database
this.products = produtos;
this.loadedProductList = produtos;
//here I just create an array with the names of the products
this.products.map( prod => {
this.productsSale.push(prod.nome);
})
})
this.productsSale = [];
}
productsCart(event) {
//here I filter the array of product names
if (event.checked == true) {
let test = this.productsSale.filter(teste => {
//here I expect to return only the items that are marked on the toogle button
return event.checked;
})
console.log(test);
}
}
<ion-toggle [(ngModel)]="item.value" class="toogle-button"
(ionChange)="productsCart($event)">
</ion-toggle>