summaryrefslogtreecommitdiff
path: root/recipeBuddy/src/app
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-12-12 11:35:58 -0500
committerTucker Evans <tuckerevans24@gmail.com>2019-12-12 11:35:58 -0500
commit6bb35f797960d200a361f10a6fa487e06a0c8e24 (patch)
treeff79546f79b3fbc9318e58ab37ab8e2534ecde2c /recipeBuddy/src/app
parent09aea62746e50d8284dc234692e7641cca03cc42 (diff)
Fix Ingredients can now be removed from cart
Diffstat (limited to 'recipeBuddy/src/app')
-rw-r--r--recipeBuddy/src/app/shopping-cart/shopping-cart.component.ts16
1 files changed, 14 insertions, 2 deletions
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 {
-
}
}