angular-cn/public/docs/_examples/style-guide/ts/07-01/app/app.component.ts

20 lines
439 B
TypeScript

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