Skip to content

Commit 5ca80ad

Browse files
author
badripaudel77
committed
clearing form, deleting ingredient from the list of ingredients implemented with conditional message rendering on UI.
1 parent 523c1b6 commit 5ca80ad

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/app/services/shopping-list.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,9 @@ export class ShoppingListService {
4646
this.ingredients.push(...addedIngredients);
4747
this.ingredientsChanged.next(this.ingredients.slice());
4848
}
49+
50+
deleteIngredient(index: number) {
51+
this.ingredients.splice(index,1);
52+
this.ingredientsChanged.next(this.ingredients.slice());
53+
}
4954
}

src/app/shopping-list/shopping-edit/shopping-edit.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ <h5>Add new ingredient</h5>
4141
<div class="col-xs-12 btn-group">
4242
<button class="btn btn-success" type="button"
4343
(click)="onIngredientAdd(shoppingForm)" [disabled]="!shoppingForm.valid">{{ editMode ? 'Update' : 'Add' }}</button>
44-
<button class="btn btn-danger">Delete</button>
45-
<button class="btn btn-warning">Clear</button>
44+
<button class="btn btn-danger" *ngIf="editMode" (click)="deleteIngredient(itemIndex)">Delete</button>
45+
<button class="btn btn-warning" (click)="clearForm()">Clear</button>
4646
</div>
4747
</div>
4848
</form>

src/app/shopping-list/shopping-edit/shopping-edit.component.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ export class ShoppingEditComponent implements OnInit, OnDestroy {
5151
},2000);
5252
}
5353

54+
clearForm() {
55+
this.shoppingListForm.reset();
56+
this.editMode = false;
57+
}
58+
59+
deleteIngredient(index: number) {
60+
this.shoppingListService.deleteIngredient(index);
61+
this.clearForm();
62+
}
63+
5464
ngOnDestroy() {
5565
// clean up , prevent memory leak
5666
this.itemEditSubscription.unsubscribe();

src/app/shopping-list/shopping-list.component.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@
99
<span>{{ingredient.name}} ({{ ingredient.amount }})</span>
1010
</a>
1111
</ul>
12+
<div class="row" style="margin-top: 15px" *ngIf="!ingredients.length">
13+
<div class="col-xs-12 alert alert-warning">
14+
No Ingredients found, please add some !
15+
</div>
16+
</div>
1217
</div>
1318
</div>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy