summaryrefslogtreecommitdiff
path: root/recipeBuddy/src/app/shopping-cart
diff options
context:
space:
mode:
authorschencej <55326070+schencej@users.noreply.github.com>2019-12-12 11:59:06 -0500
committerGitHub <noreply@github.com>2019-12-12 11:59:06 -0500
commitafd1a8106feca31ab644fbb412c87eca69bfd737 (patch)
tree639e0e9b62efbb6cac58814d39b7b8ad8529d9a9 /recipeBuddy/src/app/shopping-cart
parent677bc7c69d893faff175bb76c0948d8ef9fbeaf4 (diff)
parent6bb35f797960d200a361f10a6fa487e06a0c8e24 (diff)
Merge pull request #27 from tuckerevans/cart_update_ingredients
Fix Ingredients can now be removed from cart
Diffstat (limited to 'recipeBuddy/src/app/shopping-cart')
-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 {
-
}
}