Skip to content

Instantly share code, notes, and snippets.

@sonicoder86
Created June 24, 2016 10:58
Show Gist options
  • Save sonicoder86/a4c13b22aa0369903dedbee5141b6f08 to your computer and use it in GitHub Desktop.
Save sonicoder86/a4c13b22aa0369903dedbee5141b6f08 to your computer and use it in GitHub Desktop.
Upgrading to the new Angular 2 router - part 9
// components/hero-detail/hero-detail.component.ts
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HeroService } from '../../services/hero/hero.service'
@Component({ ... })
export class HeroDetailComponent implements OnInit {
constructor(private route: ActivatedRoute, private heroService: HeroService) {}
ngOnInit() {
this.route.params
.map(params => params.id)
.flatMap(id => this.heroService.getHero(id))
.subscribe(hero => this.hero = hero);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment