// #docregion
import {Component} from 'angular2/core';
import {LoggerService} from './logger.service';
import {Spy} from './spy.directive';
@Component({
selector: 'spy-parent',
template: `
Spy Directive
` +
// #docregion template
`
{{hero}}
`
// #enddocregion template
+ `
-- Spy Lifecycle Hook Log --
{{msg}}
`,
styles: [
'.parent {background: khaki;}',
'.heroes {background: LightYellow; padding: 0 8px}'
],
directives: [Spy],
providers: [LoggerService]
})
export class SpyParentComponent {
newName = 'Herbie';
heroes:string[] = ['Windstorm', 'Magneta'];
spyLog:string[];
constructor(private _logger:LoggerService){
this.spyLog = _logger.logs;
}
addHero() {
if (this.newName.trim()) {
this.heroes.push(this.newName.trim());
this.newName = '';
this._logger.tick();
}
}
removeHero(hero:string) {
this.heroes.splice(this.heroes.indexOf(hero), 1);
this._logger.tick();
}
reset(){
this._logger.log('-- reset --');
this.heroes.length = 0;
this._logger.tick();
}
}