File tree Expand file tree Collapse file tree 6 files changed +22
-10
lines changed Expand file tree Collapse file tree 6 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ export const routes: Routes = [
19
19
path : 'about' ,
20
20
component : AboutComponent
21
21
} ,
22
+ {
23
+ path : 'dishdetail/:id' ,
24
+ component : DishDetailComponent
25
+ } ,
22
26
{
23
27
path : 'contactus' ,
24
28
component : ContactComponent
Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ <h3>{{dish.name | uppercase}}</h3>
44
44
45
45
</ mat-list >
46
46
</ div >
47
+ < mat-card-actions >
48
+ < button mat-button (click) ="goBack() "> BACK</ button >
47
49
48
50
49
51
Original file line number Diff line number Diff line change 1
1
import { Component , Input , OnInit } from '@angular/core' ;
2
2
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' ;
3
6
4
7
@Component ( {
5
8
selector : 'app-dish-detail' ,
@@ -8,12 +11,18 @@ import {Dish} from '../shared/dish';
8
11
} )
9
12
export class DishDetailComponent implements OnInit {
10
13
11
- @Input ( )
12
14
dish : Dish ;
13
15
14
- constructor ( ) { }
16
+ constructor ( private route : ActivatedRoute , private location : Location ,
17
+ private dishService : DishService ) { }
15
18
16
19
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 ( ) ;
17
26
}
18
27
19
28
}
Original file line number Diff line number Diff line change 9
9
< div fxFlex ="40 " fxFlexOffset ="20px ">
10
10
< h4 > Links</ h4 >
11
11
< 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 >
16
16
</ mat-list >
17
17
</ div >
18
18
< div fxFlex ="55 ">
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ <h3>Menu</h3>
11
11
12
12
< div fxFlex >
13
13
< 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] ">
15
15
< img height ="200px " src ={{dish.image}} alt ={{dish.name}} >
16
16
< mat-grid-tile-footer >
17
17
< h1 > {{dish.name | uppercase}}</ h1 >
@@ -22,4 +22,3 @@ <h1>{{dish.name | uppercase}}</h1>
22
22
23
23
</ div >
24
24
25
- < app-dish-detail [dish] = "selectedDish "> </ app-dish-detail >
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';
2
2
import { Dish } from '../shared/dish' ;
3
3
import { DishService } from '../services/dish.service' ;
4
4
5
-
6
5
@Component ( {
7
6
selector : 'app-menu' ,
8
7
templateUrl : './menu.component.html' ,
@@ -22,7 +21,6 @@ selectedDish: Dish;
22
21
}
23
22
24
23
Selectdish ( dish : Dish ) {
25
- console . log ( dish ) ;
26
24
this . selectedDish = dish ;
27
25
}
28
26
You can’t perform that action at this time.
0 commit comments