angular-cn/public/docs/_examples/cb-dependency-injection/ts/app/app.component.ts

50 lines
1.6 KiB
TypeScript
Raw Normal View History

2016-03-26 12:18:13 -04:00
// #docregion
2016-04-27 14:28:22 -04:00
import { Component } from '@angular/core';
2016-03-26 12:18:13 -04:00
import { HeroBiosComponent,
HeroBiosAndContactsComponent} from './hero-bios.component';
import { HeroOfTheMonthComponent } from './hero-of-the-month.component';
import { HeroesBaseComponent,
SortedHeroesComponent } from './sorted-heroes.component';
import { HighlightDirective } from './highlight.directive';
import { ParentFinderComponent } from './parent-finder.component';
// Object Literal syntax
import { HeroOfTheMonthLiteralsComponent } from './hero-of-the-month-literals.component';
2016-03-26 12:18:13 -04:00
const DIRECTIVES = [
HeroBiosComponent, HeroBiosAndContactsComponent,
HeroesBaseComponent, SortedHeroesComponent,
HeroOfTheMonthComponent, HeroOfTheMonthLiteralsComponent,
2016-03-26 12:18:13 -04:00
HighlightDirective,
ParentFinderComponent
];
// #docregion import-services
import { LoggerService } from './logger.service';
import { UserContextService } from './user-context.service';
import { UserService } from './user.service';
@Component({
selector: 'my-app',
templateUrl: 'app/app.component.html',
2016-03-26 12:18:13 -04:00
directives: DIRECTIVES,
// #docregion providers
providers: [LoggerService, UserContextService, UserService]
// #enddocregion providers
})
export class AppComponent {
// #enddocregion import-services
private userId: number = 1;
2016-03-26 12:18:13 -04:00
// #docregion ctor
constructor(logger: LoggerService, public userContext: UserContextService) {
2016-03-26 12:18:13 -04:00
userContext.loadUser(this.userId);
logger.logInfo('AppComponent initialized');
}
// #enddocregion ctor
// #docregion import-services
}
// #enddocregion import-services