2016-04-01 17:23:34 -07:00
|
|
|
// #docplaster
|
|
|
|
|
|
|
|
// #docregion
|
|
|
|
/* recommended */
|
|
|
|
|
|
|
|
// app.component.ts
|
|
|
|
import { Component, OnInit } from 'angular2/core';
|
|
|
|
|
|
|
|
import { Hero } from './hero';
|
|
|
|
import { HeroService } from './hero.service';
|
|
|
|
|
|
|
|
@Component({
|
2016-04-25 09:24:13 -07:00
|
|
|
selector: 'toh-app',
|
2016-04-01 17:23:34 -07:00
|
|
|
template: `
|
2016-04-25 09:24:13 -07:00
|
|
|
<pre>{{heroes | json}}</pre>
|
2016-04-01 17:23:34 -07:00
|
|
|
`,
|
|
|
|
styleUrls: ['app/app.component.css'],
|
|
|
|
providers: [HeroService]
|
|
|
|
})
|
|
|
|
export class AppComponent implements OnInit{
|
|
|
|
heroes: Hero[] = [];
|
|
|
|
|
2016-04-25 09:24:13 -07:00
|
|
|
constructor(private heroService: HeroService) {}
|
2016-04-01 17:23:34 -07:00
|
|
|
|
|
|
|
ngOnInit() {
|
2016-04-25 09:24:13 -07:00
|
|
|
this.heroService.getHeroes()
|
2016-04-01 17:23:34 -07:00
|
|
|
.then(heroes => this.heroes = heroes);
|
|
|
|
}
|
|
|
|
}
|