projects
/
examples
/
angular-tour-of-heroes
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
5: Add In-app Navigation
[examples/angular-tour-of-heroes]
/
src
/
app
/
hero-detail
/
hero-detail.component.ts
diff --git
a/src/app/hero-detail/hero-detail.component.ts
b/src/app/hero-detail/hero-detail.component.ts
index
caa9c09
..
c252bcf
100644
(file)
--- a/
src/app/hero-detail/hero-detail.component.ts
+++ b/
src/app/hero-detail/hero-detail.component.ts
@@
-1,4
+1,8
@@
import { Component, OnInit, Input } from '@angular/core';
import { Component, OnInit, Input } from '@angular/core';
+import { ActivatedRoute } from '@angular/router';
+import { Location } from '@angular/common';
+
+import { HeroService } from '../hero.service';
import { Hero } from '../hero';
@Component({
import { Hero } from '../hero';
@Component({
@@
-10,9
+14,22
@@
export class HeroDetailComponent implements OnInit {
@Input() hero : Hero;
@Input() hero : Hero;
- constructor() { }
+ constructor(
+ private route: ActivatedRoute,
+ private heroService: HeroService,
+ private location: Location
+ ) { }
ngOnInit() {
ngOnInit() {
+ this.getHero();
+ }
+
+ getHero(): void {
+ const id = +this.route.snapshot.paramMap.get('id');
+ this.heroService.getHero(id).subscribe(hero => this.hero = hero);
}
}
+ goBack(): void {
+ this.location.back();
+ }
}
}