| @@ -1,11 +1,11 @@ | |||||
| <div class="row"> | <div class="row"> | ||||
| <div class="col-xs-12"> | <div class="col-xs-12"> | ||||
| <img src="" alt="" class="img-responsive"> | |||||
| <img [src]="recipe.imagePath" alt="" class="img-responsive" style="max-height: 300px;"> | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| <div class="row"> | <div class="row"> | ||||
| <div class="col-xs-12"> | <div class="col-xs-12"> | ||||
| <h1>Recipe Name</h1> | |||||
| <h1>{{ recipe.name }}</h1> | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| <div class="row"> | <div class="row"> | ||||
| @@ -26,7 +26,7 @@ | |||||
| </div> | </div> | ||||
| <div class="row"> | <div class="row"> | ||||
| <div class="col-xs-12"> | <div class="col-xs-12"> | ||||
| Description | |||||
| {{ recipe.description }} | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| <div class="row"> | <div class="row"> | ||||
| @@ -1,4 +1,5 @@ | |||||
| import { Component, OnInit } from '@angular/core'; | |||||
| import { Component, OnInit, Input } from '@angular/core'; | |||||
| import { Recipe } from '../recipe.model'; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-recipe-detail', | selector: 'app-recipe-detail', | ||||
| @@ -6,7 +7,8 @@ import { Component, OnInit } from '@angular/core'; | |||||
| styleUrls: ['./recipe-detail.component.css'] | styleUrls: ['./recipe-detail.component.css'] | ||||
| }) | }) | ||||
| export class RecipeDetailComponent implements OnInit { | export class RecipeDetailComponent implements OnInit { | ||||
| @Input() recipe: Recipe; | |||||
| constructor() { } | constructor() { } | ||||
| ngOnInit() { | ngOnInit() { | ||||
| @@ -1,9 +1,16 @@ | |||||
| <a href="#" class="list-group-item clearfix"> | |||||
| <a | |||||
| href="#" | |||||
| class="list-group-item clearfix" | |||||
| (click)="onSelected()"> | |||||
| <div class="pull-left"> | <div class="pull-left"> | ||||
| <h4 class="list-group-item-heading">{{ recipe.name }}</h4> | <h4 class="list-group-item-heading">{{ recipe.name }}</h4> | ||||
| <p class="list-group-item-text">{{ recipe.description }}</p> | <p class="list-group-item-text">{{ recipe.description }}</p> | ||||
| </div> | </div> | ||||
| <span class="pull-right"> | <span class="pull-right"> | ||||
| <img [src]="recipe.imagePath" alt="{{ recipe.name }}" class="img-responsive" style="max-height: 50px;"> | |||||
| <img | |||||
| [src]="recipe.imagePath" | |||||
| alt="{{ recipe.name }}" | |||||
| class="img-responsive" | |||||
| style="max-height: 50px;"> | |||||
| </span> | </span> | ||||
| </a> | </a> | ||||
| @@ -1,4 +1,4 @@ | |||||
| import { Component, OnInit, Input } from '@angular/core'; | |||||
| import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core'; | |||||
| import { Recipe } from '../../recipe.model'; | import { Recipe } from '../../recipe.model'; | ||||
| @Component({ | @Component({ | ||||
| @@ -8,10 +8,15 @@ import { Recipe } from '../../recipe.model'; | |||||
| }) | }) | ||||
| export class RecipeItemComponent implements OnInit { | export class RecipeItemComponent implements OnInit { | ||||
| @Input() recipe: Recipe; | @Input() recipe: Recipe; | ||||
| @Output() recipeSelected = new EventEmitter<void>(); | |||||
| constructor() { } | constructor() { } | ||||
| ngOnInit() { | ngOnInit() { | ||||
| } | } | ||||
| onSelected() { | |||||
| this.recipeSelected.emit(); | |||||
| } | |||||
| } | } | ||||
| @@ -8,6 +8,7 @@ | |||||
| <div class="col-xs-12"> | <div class="col-xs-12"> | ||||
| <app-recipe-item | <app-recipe-item | ||||
| *ngFor="let recipeElement of recipes" | *ngFor="let recipeElement of recipes" | ||||
| [recipe]="recipeElement"></app-recipe-item> | |||||
| [recipe]="recipeElement" | |||||
| (recipeSelected)="onRecipeSelected(recipeElement)"></app-recipe-item> | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| @@ -1,4 +1,4 @@ | |||||
| import { Component, OnInit } from '@angular/core'; | |||||
| import { Component, OnInit, EventEmitter, Output } from '@angular/core'; | |||||
| import { Recipe } from '../recipe.model'; | import { Recipe } from '../recipe.model'; | ||||
| @Component({ | @Component({ | ||||
| @@ -8,12 +8,18 @@ import { Recipe } from '../recipe.model'; | |||||
| }) | }) | ||||
| export class RecipeListComponent implements OnInit { | export class RecipeListComponent implements OnInit { | ||||
| recipes: Recipe[] = [ | recipes: Recipe[] = [ | ||||
| new Recipe('A Test Recipe', 'This is simlpy a test', 'http://maxpixel.freegreatpicture.com/static/photo/1x/Recipe-Soup-Noodle-Curried-Spicy-Chicken-Khaosoi-2344152.jpg') | |||||
| new Recipe('A Test Recipe', 'This is simlpy a test', 'http://maxpixel.freegreatpicture.com/static/photo/1x/Recipe-Soup-Noodle-Curried-Spicy-Chicken-Khaosoi-2344152.jpg'), | |||||
| new Recipe('Another Test Recipe', 'This is simlpy a test', 'http://maxpixel.freegreatpicture.com/static/photo/1x/Recipe-Soup-Noodle-Curried-Spicy-Chicken-Khaosoi-2344152.jpg') | |||||
| ]; | ]; | ||||
| @Output() recipeWasSelected = new EventEmitter<Recipe>(); | |||||
| constructor() { } | constructor() { } | ||||
| ngOnInit() { | ngOnInit() { | ||||
| } | } | ||||
| onRecipeSelected(recipe: Recipe) { | |||||
| this.recipeWasSelected.emit(recipe); | |||||
| } | |||||
| } | } | ||||
| @@ -1,8 +1,14 @@ | |||||
| <div class="row"> | <div class="row"> | ||||
| <div class="col-md-5"> | <div class="col-md-5"> | ||||
| <app-recipe-list></app-recipe-list> | |||||
| <app-recipe-list | |||||
| (recipeWasSelected)="selectedRecipe = $event"></app-recipe-list> | |||||
| </div> | </div> | ||||
| <div class="col-md-7"> | <div class="col-md-7"> | ||||
| <app-recipe-detail></app-recipe-detail> | |||||
| <app-recipe-detail | |||||
| *ngIf="selectedRecipe; else infoText" | |||||
| [recipe]="selectedRecipe"></app-recipe-detail> | |||||
| <ng-template #infoText> | |||||
| <p>Please select a Recipe!</p> | |||||
| </ng-template> | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| @@ -1,4 +1,5 @@ | |||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||||
| import { Recipe } from './recipe.model'; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-recipes', | selector: 'app-recipes', | ||||
| @@ -6,6 +7,7 @@ import { Component, OnInit } from '@angular/core'; | |||||
| styleUrls: ['./recipes.component.css'] | styleUrls: ['./recipes.component.css'] | ||||
| }) | }) | ||||
| export class RecipesComponent implements OnInit { | export class RecipesComponent implements OnInit { | ||||
| selectedRecipe: Recipe; | |||||
| constructor() { } | constructor() { } | ||||