Created
June 24, 2016 10:58
-
-
Save sonicoder86/a4c13b22aa0369903dedbee5141b6f08 to your computer and use it in GitHub Desktop.
Upgrading to the new Angular 2 router - part 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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