Skip to content

Commit 2f2d654

Browse files
committed
SPA part 2
1 parent 9ffb20e commit 2f2d654

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

src/app/app-routing/routes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export const routes: Routes = [
1919
path: 'about',
2020
component: AboutComponent
2121
},
22+
{
23+
path: 'dishdetail/:id',
24+
component: DishDetailComponent
25+
},
2226
{
2327
path: 'contactus',
2428
component: ContactComponent

src/app/dish-detail/dish-detail.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ <h3>{{dish.name | uppercase}}</h3>
4444

4545
</mat-list>
4646
</div>
47+
<mat-card-actions>
48+
<button mat-button (click)="goBack()">BACK</button>
4749

4850

4951

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { Component, Input, OnInit } from '@angular/core';
22
import {Dish} from '../shared/dish';
3+
import {ActivatedRoute, Params} from '@angular/router';
4+
import {Location} from '@angular/common';
5+
import {DishService} from '../services/dish.service';
36

47
@Component({
58
selector: 'app-dish-detail',
@@ -8,12 +11,18 @@ import {Dish} from '../shared/dish';
811
})
912
export class DishDetailComponent implements OnInit {
1013

11-
@Input()
1214
dish: Dish;
1315

14-
constructor() { }
16+
constructor(private route: ActivatedRoute, private location: Location,
17+
private dishService: DishService) { }
1518

1619
ngOnInit() {
20+
let id = this.route.snapshot.params['id'];
21+
this.dish = this.dishService.getDish(id);
22+
}
23+
24+
goBack (): void {
25+
this.location.back();
1726
}
1827

1928
}

src/app/footer/footer.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<div fxFlex="40" fxFlexOffset="20px">
1010
<h4>Links</h4>
1111
<mat-list>
12-
<mat-list-item><a mat-button>Home</a></mat-list-item>
13-
<mat-list-item><a mat-button>About</a></mat-list-item>
14-
<mat-list-item><a mat-button>Menu</a></mat-list-item>
15-
<mat-list-item><a mat-button>Contact</a></mat-list-item>
12+
<mat-list-item><a mat-button routerLink='/home'>Home</a></mat-list-item>
13+
<mat-list-item><a mat-button routerLink='/About'>About</a></mat-list-item>
14+
<mat-list-item><a mat-button routerLink='/Menu'>Menu</a></mat-list-item>
15+
<mat-list-item><a mat-button routerLink='/Contactus'>Contact</a></mat-list-item>
1616
</mat-list>
1717
</div>
1818
<div fxFlex="55">

src/app/menu/menu.component.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h3>Menu</h3>
1111

1212
<div fxFlex>
1313
<mat-grid-list cols="2" rowHeight="200px">
14-
<mat-grid-tile *ngFor="let dish of dishes" (click)="Selectdish(dish)">
14+
<mat-grid-tile *ngFor="let dish of dishes" [routerLink]="['/dishdetail',dish.id]">
1515
<img height="200px" src={{dish.image}} alt={{dish.name}}>
1616
<mat-grid-tile-footer>
1717
<h1>{{dish.name | uppercase}}</h1>
@@ -22,4 +22,3 @@ <h1>{{dish.name | uppercase}}</h1>
2222

2323
</div>
2424

25-
<app-dish-detail [dish] = "selectedDish"></app-dish-detail>

src/app/menu/menu.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';
22
import {Dish} from '../shared/dish';
33
import {DishService} from '../services/dish.service';
44

5-
65
@Component({
76
selector: 'app-menu',
87
templateUrl: './menu.component.html',
@@ -22,7 +21,6 @@ selectedDish: Dish;
2221
}
2322

2423
Selectdish(dish: Dish){
25-
console.log(dish);
2624
this.selectedDish = dish;
2725
}
2826

0 commit comments

Comments
 (0)