// #docplaster
// #docregion
// #docregion imports
import { Component, Inject } from '@angular/core';
import { CarComponent } from './car/car.component';
import { HeroesComponent } from './heroes/heroes.component';
import { APP_CONFIG, AppConfig,
HERO_DI_CONFIG } from './app.config';
import { Logger } from './logger.service';
import { UserService } from './user.service';
// #enddocregion imports
import { InjectorComponent } from './injector.component';
import { TestComponent } from './test.component';
import { ProvidersComponent } from './providers.component';
@Component({
selector: 'my-app',
template: `
{{title}}
User
{{userInfo}}
`,
directives: [CarComponent, HeroesComponent,
InjectorComponent, TestComponent, ProvidersComponent],
// #docregion providers
providers: [
Logger,
UserService,
{ provide: APP_CONFIG, useValue: HERO_DI_CONFIG }
]
// #enddocregion providers
})
export class AppComponent {
title: string;
// #docregion ctor
constructor(
@Inject(APP_CONFIG) config: AppConfig,
private userService: UserService) {
this.title = config.title;
}
// #enddocregion ctor
get isAuthorized() { return this.user.isAuthorized; }
nextUser() { this.userService.getNewUser(); }
get user() { return this.userService.user; }
get userInfo() {
return `Current user, ${this.user.name}, is ` +
`${this.isAuthorized ? '' : 'not'} authorized. `;
}
}