angular-cn/public/docs/_examples/tutorial/ts/app/hero-detail.component.ts

29 lines
659 B
TypeScript

import {Component, OnInit} from 'angular2/core';
import {RouteParams} from 'angular2/router';
import {Hero} from './hero';
import {HeroService} from './hero.service';
@Component({
selector: 'my-hero-detail',
templateUrl: 'app/hero-detail.component.html',
inputs: ['hero']
})
export class HeroDetailComponent implements OnInit {
public hero: Hero;
constructor(private _heroService: HeroService,
private _routeParams: RouteParams) {
}
ngOnInit() {
if (!this.hero) {
let id = +this._routeParams.get('id');
this._heroService.getHero(id).then(hero => this.hero = hero);
}
}
goBack() {
window.history.back();
}
}