2015-11-21 11:23:40 -08:00
|
|
|
// #docregion
|
2016-01-23 18:21:09 +00:00
|
|
|
import {Directive, OnInit, OnDestroy} from 'angular2/core';
|
2015-11-21 11:23:40 -08:00
|
|
|
import {LoggerService} from './logger.service';
|
|
|
|
|
|
|
|
let nextId = 1;
|
|
|
|
|
2016-01-23 18:21:09 +00:00
|
|
|
// #docregion spy-directive
|
2015-11-21 11:23:40 -08:00
|
|
|
// Spy on any element to which it is applied.
|
|
|
|
// Usage: <div my-spy>...</div>
|
|
|
|
@Directive({selector: '[my-spy]'})
|
|
|
|
export class Spy implements OnInit, OnDestroy {
|
|
|
|
|
2016-01-23 18:21:09 +00:00
|
|
|
constructor(private _logger:LoggerService) { }
|
2015-11-21 11:23:40 -08:00
|
|
|
|
2016-01-23 18:21:09 +00:00
|
|
|
ngOnInit() { this._logIt(`onInit`); }
|
2015-11-21 11:23:40 -08:00
|
|
|
|
2016-01-23 18:21:09 +00:00
|
|
|
ngOnDestroy() { this._logIt(`onDestroy`); }
|
2015-11-21 11:23:40 -08:00
|
|
|
|
|
|
|
private _logIt(msg:string){
|
2016-01-23 18:21:09 +00:00
|
|
|
this._logger.log(`Spy #${nextId++} ${msg}`);
|
2015-11-21 11:23:40 -08:00
|
|
|
}
|
|
|
|
}
|
2016-01-23 18:21:09 +00:00
|
|
|
// #enddocregion spy-directive
|