|
1 | 1 | // #docregion
|
2 |
| -import {Component,OnInit} from 'angular2/core'; |
3 |
| -import {LoggerService} from './logger.service'; |
4 |
| -import {UserContext} from './user-context.service'; |
5 |
| -import {Heroes} from './hero-bios.component'; |
6 |
| -import {SortedHeroes} from './sorted-heroes.component'; |
7 |
| -import {HeroOfTheMonth} from './hero-of-the-month.component'; |
| 2 | +import { Component } from 'angular2/core'; |
| 3 | + |
| 4 | +import { HeroBiosComponent, |
| 5 | + HeroBiosAndContactsComponent} from './hero-bios.component'; |
| 6 | +import { HeroOfTheMonthComponent } from './hero-of-the-month.component'; |
| 7 | +import { HeroesBaseComponent, |
| 8 | + SortedHeroesComponent } from './sorted-heroes.component'; |
| 9 | + |
| 10 | +// #docregion import-services |
| 11 | +import { LoggerService } from './logger.service'; |
| 12 | +import { UserContextService } from './user-context.service'; |
| 13 | +import { UserService } from './user.service'; |
| 14 | +// #enddocregion import-services |
8 | 15 |
|
9 | 16 | @Component({
|
10 | 17 | selector: 'my-app',
|
11 |
| - directives:[Heroes,SortedHeroes,HeroOfTheMonth], |
12 |
| - template: |
13 |
| - `<h1>DI Components</h1> |
14 |
| - <div class="di-component"> |
15 |
| - <h3>Logged in user</h3> |
16 |
| - <div>Name: {{_userContext.name}}</div> |
17 |
| - <div>Role: {{_userContext.role}}</div> |
18 |
| - </div> |
19 |
| - |
20 |
| - <div class="di-component"> |
21 |
| - <h3>Sorted Heroes</h3> |
22 |
| - <sorted-heroes></sorted-heroes> |
23 |
| - </div> |
24 |
| - |
25 |
| - <div class="di-component"> |
26 |
| - <h3>Hero of the month</h3> |
27 |
| - <hero-of-the-month></hero-of-the-month> |
28 |
| - </div> |
29 |
| - |
30 |
| - <div class="di-component"> |
31 |
| - <h3>Hero Bios</h3> |
32 |
| - <hero-bios></hero-bios> |
33 |
| - </div>` |
| 18 | + templateUrl:'app/app.component.html', |
| 19 | + directives: [ |
| 20 | + HeroBiosComponent, HeroBiosAndContactsComponent, |
| 21 | + HeroesBaseComponent, SortedHeroesComponent, |
| 22 | + HeroOfTheMonthComponent |
| 23 | + ], |
| 24 | +// #docregion providers |
| 25 | + providers: [LoggerService, UserContextService, UserService] |
| 26 | +// #enddocregion providers |
34 | 27 | })
|
35 | 28 |
|
36 |
| -export class AppComponent implements OnInit { |
37 |
| - |
| 29 | +export class AppComponent { |
| 30 | + |
38 | 31 | private userId:number = 1;
|
39 |
| - |
40 |
| - constructor(private _logger:LoggerService, private _userContext:UserContext){ |
41 |
| - this._userContext.loadUser(this.userId); |
42 |
| - } |
43 |
| - |
44 |
| - ngOnInit(){ |
45 |
| - this._logger.logInfo('AppComponent initialized'); |
| 32 | + |
| 33 | + // #docregion ctor |
| 34 | + constructor(logger:LoggerService, public userContext:UserContextService) { |
| 35 | + userContext.loadUser(this.userId); |
| 36 | + logger.logInfo('AppComponent initialized'); |
46 | 37 | }
|
| 38 | + // #enddocregion ctor |
47 | 39 | }
|
0 commit comments