Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: How to update the same component with different params.


I've done the tour of heroes from angular. It works perfectly.

Now I want to put the Dashboard Component in the hero detail view. So it shows me the top of heroes, and after that, the hero detail view. Image

I have a Router link that loads the same component, but with different params. I want to know, what to do so that when I click on any element from the dashboard this one load a different hero.

This is the code of the hero-detail.component.html




hero detail class

export class HeroDetailComponent implements OnInit {
@Input() hero: Hero;

private route: ActivatedRoute,

private heroService: HeroService,

private location: Location
) {}

ngOnInit(): void {

getHero(): void {
const id = +this.route.snapshot.paramMap.get('id');
.subscribe(hero => this.hero = hero);

goBack(): void {
save(): void {
.subscribe(() => this.goBack());

The dashboard code

The router is the same as the tutorial.

const routes: Routes = [
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
{ path: 'dashboard', component: DashboardComponent },
{ path: 'heroes', component: HeroesComponent },
{ path: 'detail/:id', component: HeroDetailComponent }

A bad solution:

After research a little i found the possibility to add the (click)="reloadRoute()" to the link, but this one refresh all the page.

Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered

This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: How to update the same component with different params.


Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription