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

19 lines
457 B
TypeScript

import { Component, OnInit } from '@angular/core';
import { Hero, HeroCollectorService } from './core';
@Component({
selector: 'sg-app',
template: '<div>Our hero is {{hero.name}} and {{hero.power}}</div>',
providers: [HeroCollectorService]
})
export class AppComponent implements OnInit {
hero: Hero;
constructor(private heroCollectorService: HeroCollectorService) { }
ngOnInit() {
this.hero = this.heroCollectorService.getHero();
}
}