angular-docs-cn/public/docs/_examples/style-guide/ts/03-05/app/app.component.ts

23 lines
654 B
TypeScript

import { Component, OnInit } from '@angular/core';
import { Hero, HeroService } from './+heroes';
import { ExceptionService, SpinnerService, ToastService } from './shared';
@Component({
moduleId: module.id,
selector: 'sg-app',
templateUrl: 'app.component.html',
providers: [HeroService, ExceptionService, SpinnerService, ToastService]
})
export class AppComponent implements OnInit {
favorite: Hero;
heroes: Hero[];
constructor(private heroService: HeroService) { }
ngOnInit() {
this.heroService.getHero(1).subscribe(hero => this.favorite = hero);
this.heroService.getHeroes().subscribe(heroes => this.heroes = heroes);
}
}