Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
bonus
  • Loading branch information
Georginapacey committed Sep 9, 2018
commit 904193f1634f2dc35f93c358a7055aa5f241080a
8 changes: 4 additions & 4 deletions starter-code/src/app/food-list/food-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
<img [src]="food.image" alt="">
<h4>{{food.name}}</h4>
<p>Calories: {{food.calories}}</p>
<input type="number" placeholder="quantity" [(ngModel)]="food.quantity">
<input type="number" [(ngModel)]="food.quantity">
<button (click)="onClickAddFood(food)">Add</button>
</div>
</div>
</div>
<div class="col-4">
<div class="row">
<h4>Food for today:</h4>
<div>
<div class="d-block">
<ul *ngFor="let selectedFood of selectedFoods">
<li>&nbsp;{{selectedFood.name}} x{{selectedFood.quantity}}</li>
<li>{{selectedFood.name}} x{{selectedFood.quantity}}</li>
</ul>
</div>
<div>
<p>total calories:</p>
<h4>total calories: {{totalCalories}}</h4>
</div>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion starter-code/src/app/food-list/food-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class FoodListComponent {
foodToCreate: Food = new Food();
selectedFoods: Array<Food> = [];
totalCalories: number = 0;


onClickCreateFood(): void {
this.foods.push(this.foodToCreate);
Expand All @@ -20,6 +19,10 @@ export class FoodListComponent {

onClickAddFood(foodItem): void {
this.selectedFoods.push(foodItem);
if (foodItem.quantity == 0) {
foodItem.quantity++;
}
this.totalCalories += (foodItem.calories * foodItem.quantity);
}


Expand Down
2 changes: 1 addition & 1 deletion starter-code/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ img {
max-width: 100%;
}

h4 {
h4, .d-block {
width: 100%;
}