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
Iteration 3: Add new foods done
  • Loading branch information
jhmatienza committed Sep 15, 2018
commit 66b8fbfeb6a1f03ef5d4e5e85f70e103525e2019
33 changes: 31 additions & 2 deletions starter-code/src/app/food-list/food-list.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
<div class="container">
<h1>Search food</h1>
<input type="text" class="form-control" placeholder="Search food..." name="searchFood" [(ngModel)]="searchFood" style="width:500px">

<br>
<h1>Food list</h1>
<div *ngFor="let food of foods | foodFinder: searchFood" class="card" style="width: 18rem;">
<img class="card-img-top" src="{{food.image}}" alt="food">
<div class="card-body">
<h5 class="card-title" name="name">{{food.name}}</h5>
<p class="card-text">{{food.calories}} Calories</p>
</div>
</div>
</div>
<br>
<button type="button" (click)="showForm()" class="btn btn-secondary">Add Food</button>
</div>
<br>
<form class="container" *ngIf="showAddForm">
<div class="form-group">
<label for="foodName">Food Name</label>
<input type="text" class="form-control col-md-6" name="name" [(ngModel)]="newFood.name" placeholder="Food name"
required>
</div>
<div class="form-group">
<label for="calories">Calories</label>
<input type="number" class="form-control col-md-6" name="calories" [(ngModel)]="newFood.calories" placeholder="Calores"
required>
</div>
<div class="form-group">
<label for="image">Image</label>
<input type="text" class="form-control col-md-6" name="image" [(ngModel)]="newFood.image" placeholder="Image"
required>
</div>
<div class="form-group">
<label for="quantity">Quantity</label>
<input type="number" class="form-control col-md-6" name="quantity" [(ngModel)]="newFood.quantity" placeholder="Quantity"
required>
</div>

<button type="button" (click)="addFood()" class="btn btn-primary">Save</button>
</form>
16 changes: 15 additions & 1 deletion starter-code/src/app/food-list/food-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import foods from '../foods';
import foods from '../foods';

@Component({
selector: 'app-food-list',
Expand All @@ -9,5 +9,19 @@ import foods from '../foods';
export class FoodListComponent {
foods: Array<Object> = foods;
searchFood: string;
newFood: Object = {};
showAddForm: boolean = false;

addFood(): void {
this.foods.push(this.newFood);
this.newFood = {};
this.showAddForm = false;
}

showForm(): void {
this.showAddForm = !this.showAddForm;
}
}