2016-03-26 12:18:13 -04:00
|
|
|
// #docplaster
|
|
|
|
// #docregion
|
2016-06-12 18:41:33 -04:00
|
|
|
import { Component, Host, Optional } from '@angular/core';
|
2016-05-03 08:06:32 -04:00
|
|
|
|
|
|
|
import { HeroCacheService } from './hero-cache.service';
|
|
|
|
import { LoggerService } from './logger.service';
|
2016-03-26 12:18:13 -04:00
|
|
|
|
|
|
|
// #docregion component
|
|
|
|
@Component({
|
2016-06-07 19:06:25 -04:00
|
|
|
selector: 'hero-contact',
|
|
|
|
template: `
|
2016-03-26 12:18:13 -04:00
|
|
|
<div>Phone #: {{phoneNumber}}
|
|
|
|
<span *ngIf="hasLogger">!!!</span></div>`
|
|
|
|
})
|
|
|
|
export class HeroContactComponent {
|
|
|
|
|
|
|
|
hasLogger = false;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
// #docregion ctor-params
|
|
|
|
@Host() // limit to the host component's instance of the HeroCacheService
|
2016-05-03 08:06:32 -04:00
|
|
|
private heroCache: HeroCacheService,
|
2016-03-26 12:18:13 -04:00
|
|
|
|
|
|
|
@Host() // limit search for logger; hides the application-wide logger
|
|
|
|
@Optional() // ok if the logger doesn't exist
|
2016-05-03 08:06:32 -04:00
|
|
|
private loggerService: LoggerService
|
2016-03-26 12:18:13 -04:00
|
|
|
// #enddocregion ctor-params
|
|
|
|
) {
|
2016-05-03 08:06:32 -04:00
|
|
|
if (loggerService) {
|
2016-03-26 12:18:13 -04:00
|
|
|
this.hasLogger = true;
|
2016-05-03 08:06:32 -04:00
|
|
|
loggerService.logInfo('HeroContactComponent can log!');
|
2016-03-26 12:18:13 -04:00
|
|
|
}
|
|
|
|
// #docregion ctor
|
|
|
|
}
|
|
|
|
// #enddocregion ctor
|
|
|
|
|
2016-05-03 08:06:32 -04:00
|
|
|
get phoneNumber() { return this.heroCache.hero.phone; }
|
2016-03-26 12:18:13 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
// #enddocregion component
|