-import { Component, OnInit, Input } from '@angular/core';
+import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common';
})
export class HeroDetailComponent implements OnInit {
- @Input() hero : Hero;
+ hero: Hero;
constructor(
private route: ActivatedRoute,
}
getHero(): void {
- const id = +this.route.snapshot.paramMap.get('id');
- this.heroService.getHero(id).subscribe(hero => this.hero = hero);
+ this.route.params.subscribe(params => {
+ const id: number = +params.id;
+ this.heroService.getHero(id).subscribe(hero => this.hero = hero);
+ });
}
goBack(): void {