// #docregion import {Component, OnInit} from 'angular2/core'; import {Hero, HeroService} from './hero.service'; import {RouteParams, Router} from 'angular2/router'; @Component({ template: `

HEROES

"{{hero.name}}"

{{hero.id}}

`, }) export class HeroDetailComponent implements OnInit { hero: Hero; // #docregion ctor constructor( private _router:Router, private _routeParams:RouteParams, private _service:HeroService){} // #enddocregion ctor // #docregion ngOnInit ngOnInit() { let id = this._routeParams.get('id'); this._service.getHero(id).then(hero => this.hero = hero); } // #enddocregion ngOnInit // #docregion gotoHeroes gotoHeroes() { let heroId = this.hero ? this.hero.id : null; // Pass along the hero id if available // so that the HeroList component can select that hero. // Add a totally useless `foo` parameter for kicks. // #docregion gotoHeroes-navigate this._router.navigate(['Heroes', {id: heroId, foo: 'foo'} ]); // #enddocregion gotoHeroes-navigate } // #enddocregion gotoHeroes }