X-Git-Url: https://juplo.de/gitweb/?p=examples%2Fangular-tour-of-heroes;a=blobdiff_plain;f=src%2Fapp%2Fhero-detail%2Fhero-detail.component.ts;h=c252bcffe4905eb339cd4ecbd01d71c7690a29f6;hp=caa9c091e162601ab48c8c6d150e1aa7c2ac6aa4;hb=f18faff7c576b595dd8765f36805aa8176122db7;hpb=0e69f63239442f2533e2c84f1de9179e726eaf04 diff --git a/src/app/hero-detail/hero-detail.component.ts b/src/app/hero-detail/hero-detail.component.ts index caa9c09..c252bcf 100644 --- 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 { ActivatedRoute } from '@angular/router'; +import { Location } from '@angular/common'; + +import { HeroService } from '../hero.service'; import { Hero } from '../hero'; @Component({ @@ -10,9 +14,22 @@ export class HeroDetailComponent implements OnInit { @Input() hero : Hero; - constructor() { } + constructor( + private route: ActivatedRoute, + private heroService: HeroService, + private location: Location + ) { } 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(); + } }