From 6bb35f797960d200a361f10a6fa487e06a0c8e24 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Thu, 12 Dec 2019 11:35:58 -0500 Subject: Fix Ingredients can now be removed from cart --- .../src/app/shopping-cart/shopping-cart.component.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'recipeBuddy/src') diff --git a/recipeBuddy/src/app/shopping-cart/shopping-cart.component.ts b/recipeBuddy/src/app/shopping-cart/shopping-cart.component.ts index 26808ee..b60a63c 100644 --- a/recipeBuddy/src/app/shopping-cart/shopping-cart.component.ts +++ b/recipeBuddy/src/app/shopping-cart/shopping-cart.component.ts @@ -34,6 +34,10 @@ export class ShoppingCartComponent implements OnInit { for(i = 0; i < res.length; i++) { this.restService.getRecipe(res[i]).subscribe( res2 => { + for (var j = 0; j < res2.ingredients.length; j++) { + res2.ingredients[j]["checked"] = false; + res2.ingredients[j]["cart_index"] = -1; + } this.recipes.push(res2) }); } @@ -53,10 +57,18 @@ export class ShoppingCartComponent implements OnInit { } addIngredient(ing: Ingredient): void { - this.ingredients.push(ing); + ing.checked = !ing.checked; + if (ing.checked){ + this.ingredients.push(ing); + ing.cart_index = this.ingredients.length - 1; + } else { + this.ingredients.splice(ing.cart_index, 1); + for(var i = 0; i < this.ingredients.length; i++) { + this.ingredients[i].cart_index = i; + } + } } printList(): void { - } } -- cgit v1.1